Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dvman

macrumors newbie
Original poster
Jul 27, 2010
1
0
How do I autostart background music in Safari and stop it via javascript?

I tried setting the data to a false mp3 but it does not seem to work in Safari (on Windows) it only works in FireFox. (Internet Explorer does not even play the mp3.)

Here is HTML:
<OBJECT ID="BackgroundMusic" DATA="music/background.mp3" TYPE="audio/mpeg" height="0" width="0">
<PARAM NAME="autostart" VALUE="true">
<PARAM NAME="hidden" VALUE="true">
</OBJECT>


<p class="music" onClick="StopBackgroundMusic()">Stop Music</p>

Here is javascript

function StopBackgroundMusic()
{
var MusicObj = document.getElementById("BackgroundMusic");
MusicObj.data = "nothing.mp3";
MusicObj.autoplay = "false";
MusicObj.autostart = "false";
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.