PDA

View Full Version : Simple Javascript Problem



fileserverdirect
12-21-2007, 11:11 PM
PULLING MY HAIR OUT!!!!
I have TRYED to work out this bug BEFORE going to DD for help (so don't get up in my grill:D), because I always say to myslef "Come on, you don't need to ask for help with a problem like this". I fianly broke loose, and decided to post. When you press the button, it is suposed to open Windows Media Player and play the song that was in the address bar. It works fine with the link...

<html>
<head>
<style>
html, body
{
scrollbar-face-color:#EBF5FF;
scrollbar-base-color:#EBF5FF;
scrollbar-arrow-color:black;
scrollbar-track-color:#F3F3F3;
scrollbar-shadow-color:#EBF5FF;
scrollbar-highlight-color:#EBF5FF;
scrollbar-3dlight-color:#78AAFF;
scrollbar-darkshadow-Color:#78AAFF;
}
container
{border:1px solid black; background-color: lightyellow;}
</style>
<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1]; }
}
return "";
}
var song = getQueryVariable("song");
var mp3 = getQueryVariable("mp3");
document.title="Download: "+song;
</script>
</head>
<body background="bg.jpg">

<script> document.write('<form action="C:\\Documents and Settings\\Pip\\Desktop\\Bob Grawi\\'+mp3+'"><center><h2>Download '+song+'</h2></center>');</script>
<div class="container" style="padding: 5px;">
<script>
document.write('<center><input type="submit" value="Download '+song+'"></center>');
//document.write('<a href="C:\\Documents a[removed]b Grawi\\'+mp3+'">Download</a>')
</script>
</div>
</form>
</body>

</html>

HELP!

jscheuer1
12-22-2007, 08:44 AM
IDK, it's working for me here, though I did use an mp3 file from the web, not my hard drive. One thing I would do is unescape the query value:


return unescape(pair[1]); }

But that's just for cosmetic purposes.

Are you sure you are feeding it a valid URL, like:


page.htm?mp3=web.mp3&song=Love Shuffle

?

The code could be more standard, but I got the impression that you don't care about that.

jscheuer1
12-22-2007, 09:17 AM
I was thinking about this, and maybe being on the web has something to do with it because of the path. If you are using your local machine, perhaps you should make this:


C:\\Documents a[removed]b Grawi\\

a web type path:


file://localhost/C:/Documents%20a[removed]b%20Grawi/

fileserverdirect
12-22-2007, 04:42 PM
Thanks! The uirl was the problem,
BTW, This script was part of the kiosk script that I got to work!

jscheuer1
12-22-2007, 08:17 PM
Just out of curiosity, was it the this type URL:


page.htm?mp3=web.mp3&song=Love Shuffle

or this one:


C:\\Documents a[removed]b Grawi\\

?

fileserverdirect
12-23-2007, 03:20 PM
Sorry, I un-subscribed from this post, so I did not know you posted until now...
The second one :)

jscheuer1
12-23-2007, 08:16 PM
Thanks, saved me the trouble of playing around with it some more, that will earn you some free advice:

It probably isn't a good idea to post the directory structure of your local disk in a public forum.

Now I don't know if you actually did that or not, but it looked like you might have.