PDA

View Full Version : ON/OFF Music script not working in IE



jaiantbass
01-08-2009, 06:26 AM
So I have been trying to use this script by John Sheuer for bg music. It works great except in IE. I have tried a hundred different ways, but can't seem to get it working in IE. I have looked back through the other threads on the subject to no avail. Any help out there?

Here is what I have:



<script type="text/javascript">
/*Toggle Sound Script John Davenport Scheuer
as first seen in www.dynamicdrive.com/forums (user name:
jscheuer1). Visit http://www.dynamicdrive.com for 100's
of DHTML scripts. This credit must remain for legal use.
*/
var sndEl="HomePage/Mixdown.mp3" //Set to name and path of your sound file
function toggleSound(){
if (document.all&&document.all.sound&&document.all.sound.src!=='')
document.all.sound.src=''
else if (document.getElementById&&document.getElementById('snd')){
sndEl=document.getElementById('snd')
document.getElementById('sndC').removeChild(sndEl)
}
else if (document.all&&document.all.sound&&document.all.sound.src=='')
document.all.sound.src=sndEl
else if (document.getElementById)
document.getElementById('sndC').appendChild(sndEl)
}
</script>




<script type="text/javascript">
if(document.getElementById&&!document.getElementById('sound')){
document.write('<div id="sndC" style="position:absolute;top:-1000px:left:-1000px;visibility:hidden;">')

document.write('<embed id="snd" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" Name="MediaPlayer" src="'+sndEl+'" AUTOSTART="true" hidden="true" loop="true">')

document.write('</div>')
}
document.write('<input type="image" class="centerd" src="HomePage/Music.gif" onclick="toggleSound();">')
</script>


Thanks,

Andrew

jscheuer1
01-08-2009, 07:46 AM
That's one of the earlier versions of the code. It had at least several updates over the years as browsers changed. And, although I haven't revisited this concept in a while, the last installment is still working fine in IE:

http://loisimages.com/john/music/music_adv_dd.htm

Use your browser's 'view source' to get the code.

jaiantbass
01-09-2009, 01:36 AM
Thanks John, I will give this a try.

Andrew

jaiantbass
01-10-2009, 01:09 AM
John,

Could you take a look at what I have done here:

www.edrafting.homeip.net

The music won't play for some reason.

Thanks again,

Andrew

jscheuer1
01-10-2009, 03:37 AM
First of all, you are using Swiss Army Slide Show with no credit in your page's source code. That is in violation of DD TOS:

Your page is in violation of Dynamic Drive's usage terms (http://www.dynamicdrive.com/notice.htm), which, among other things, state that the script credit must appear in the source code of the page(s) using the script. Please reinstate the notice first.

You may also be using other scripts (DD scripts or others) in violation of their TOS, I just happened to notice that one, perhaps because I wrote it and could easily see that it was being used.

Please make sure that you are crediting all scripts whose Terms Of Service require it.

That said, as for the Toggle Sound Script III script, you have an onload conflict, and you left out some code. To fix the onload conflict, get rid of this (highlighted):


<body onload="Load('slide');" >

Move its code to here (also highlighted):


onload=function(){toggleSound(document.images.bob);
if(document.getElementById&&document.getElementById('sndC'))
document.getElementById('sndC').style.display='';
if(start_music_onload){
Load('slide');
toggleSound(document.images.bob);
document.images.bob.src = document.images.bob.lowsrc;
};
};

As for the missing code, add it back (highlighted) here:


. . . kground-color:#D1E5EF;
}
</style>


</head>

<body>
<!--[if IE]>
<script type="text/javascript">
if(mpIsInstalled)
document.write('<object id="sound" height="0" width="0"'+
' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">\n'+
'<param name="playCount" value="20000">\n'+
'<\/object>\n');
else
document.write('<bgsound id="sound" src="" loop="-1">')
</script>
<![endif]-->
<div id="maincontent">
<div id="box1" class="slide :-650:-50 . . .

Working here in the three browsers I've tested (FF, Opera, and IE).

jaiantbass
01-10-2009, 05:45 AM
John,

I must have accidentally deleted out the credit's. I will fix this right away, my apologies. I was just talking to someone about making sure the credits where there when using other peoples scripts (and even showed them your sound script with your credits in it). Very embarrassing on my part. Being very new to javascript, I have found that your scripts have been very easy to follow and appreciate everything. Thanks again for your help.

Andrew

jaiantbass
01-10-2009, 06:02 AM
John,

In my rush, I missed how to appropriately give credit when using external .js files. I left them in the original .js files but didn't realize they didn't show up in the source code. I have fixed it and thank you for correcting me.

Andrew