webill
06-30-2008, 03:57 PM
Hi folks, I have a code for music on/off that finally works in all browsers but in IE7 to turn off the sound I have to click the off button many times before it quits the music....
Can any good soul help me out on this one?
Hereafter the code, thanks a lot!
<body id="bodyMain" onload="javascript:soundCtrl('on')">
<script language="javascript" type="text/javascript">
var soundSource="../audio/tequila.mp3";
function soundCtrl(onoff) {
if(onoff == "off") {
var sound = el("bgsound");
if(sound)
document.getElementById("bodyMain").removeChild(sound);
}
else if(onoff == "on"){
if(el("bgsound")) return;
var sound = document.createElement("embed");
sound.setAttribute("src",soundSource);
sound.setAttribute("hidden",true);
sound.setAttribute("autostart",true);
sound.setAttribute("id","bgsound");
document.getElementById("bodyMain").appendChild(sound);
}
}
function el(id) {
var el = document.getElementById(id);
return el;
}
</script>
HTML
<a href="#" onclick="soundCtrl('off')">shut up |</a>
<a href="#" onclick="soundCtrl('on')">play on</a>
Can any good soul help me out on this one?
Hereafter the code, thanks a lot!
<body id="bodyMain" onload="javascript:soundCtrl('on')">
<script language="javascript" type="text/javascript">
var soundSource="../audio/tequila.mp3";
function soundCtrl(onoff) {
if(onoff == "off") {
var sound = el("bgsound");
if(sound)
document.getElementById("bodyMain").removeChild(sound);
}
else if(onoff == "on"){
if(el("bgsound")) return;
var sound = document.createElement("embed");
sound.setAttribute("src",soundSource);
sound.setAttribute("hidden",true);
sound.setAttribute("autostart",true);
sound.setAttribute("id","bgsound");
document.getElementById("bodyMain").appendChild(sound);
}
}
function el(id) {
var el = document.getElementById(id);
return el;
}
</script>
HTML
<a href="#" onclick="soundCtrl('off')">shut up |</a>
<a href="#" onclick="soundCtrl('on')">play on</a>