Forum Moderators: open

Message Too Old, No Replies

bg Sound Changer

whats wrong wih my code?

         

electricocean

4:23 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



I want to chage the bgsound file on my site

I have been trying this:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function playMusic(MFILE)
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) ¦¦ (OPER>-1)) {
document.write("<BGSOUND SRC="mp3/+MFILE+.mp3" LOOP="INFINITE">");
} else {
document.write("<EMBED SRC="mp3/+MFILE+.mp3" AUTOSTART="TRUE" HIDDEN=true VOLUME=100 LOOP=TRUE>");
}
// End -->
</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<select name="bgsound">
<option value="javascript:playMusic('uncle#*$!er')" selectted>Uncle #*$!er
<option value="javascript:playMusic('whatwouldbrianboitanodo')">What would Brian Boitano do?
<option value="javascript:playMusic('blamecanada')">Blame Canada
<option value=""javascript:playMusic('')"">Disable music
</select>
</body>
</html>

it wont work... whats wrong with it?

Bernard Marx

7:27 pm on Nov 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. String concatenation:

document.write("<BGSOUND SRC="mp3/+MFILE+.mp3" LOOP="INFINITE">");

should be:

document.write('<BGSOUND SRC="mp3/'+MFILE+'.mp3" LOOP="INFINITE">');

2. Value attribute of option element won't execute javascript protocol.

electricocean

10:45 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



then how should i do it?

adni18

1:50 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function playMusic(MFILE)
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) ¦¦ (OPER>-1)) {
document.write('<EMBED SRC="mp3/'+MFILE+'.mp3" LOOP="INFINITE">');
} else {
document.write('<BGSOUND SRC="mp3/'+MFILE+'.mp3" LOOP="INFINITE">');
}
// End -->
</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<select name="bgsound">
<option value="javascript:playMusic('uncle#*$!er')" selectted>Uncle #*$!er
<option value="javascript:playMusic('whatwouldbrianboitanodo')">What would Brian Boitano do?
<option value="javascript:playMusic('blamecanada')">Blame Canada
<option value=""javascript:playMusic('')"">Disable music
</select>
</body>
</html>

Make sure you replace these broken pipes (¦) to real ones. The forum software changes them, unfortunately.

adni18

1:53 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way, why do you need
var NETS=navigator.userAgent.indexOf("Netscape");

? You don't ever call up NETS later in your scripting.

electricocean

2:06 am on Nov 15, 2004 (gmt 0)

10+ Year Member



I don't know why it's there... I got the code off [javascript.internet.com...] and put the function in it.