2012-11-10 27 views
-1

我用下面的腳本播放2個聲音文件的工作一個純滯後多發的setTimeout不是在Firefox和IE

<html> 
<head> 
<script language="javascript" type="text/javascript"> 
    function playSound(soundfile,soundfile1) 
    { 
     document.getElementById("sound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"true\" />"; 
     setTimeout(function(){document.write ('<EMBED src= "' + soundfile1 + '" hidden=true autostart=true loop=false>')},2000); 
     setTimeout(function(){alert("You have successfully launched the MedOrient website! \n Thank you for launching Sri sai medical jobs.");},3000); 
     setTimeout("window.location='http://url'",8000); 
    } 
</script> 
</head> 

<body> 
    <a href="#" onclick="playSound('clapping.mp3','fireworks56.mp3');" ><img src="ribbon-cutting.jpg"/></a> 
</body> 
</html> 

這是使用Chrome之後,但不是在Firefox或IE瀏覽器的工作。 soundfile1(fireworks56.mp3)在少量(約8秒)後播放,但不會重定向。 在Firefox狀態欄中它表明,

Read http://url 
+1

**文件加載後切勿使用文件撰寫。** 如果你沒有支持老版本的IE瀏覽器,使用HTML5音頻元素進行調查。 – zetlen

+0

我在播放媒體和重定向時有目的地使用了'document.write'來顯示一個空白頁面。 – Thiru

回答

1

不要使用document.write,將覆蓋新的內容頁面。

嘗試下面的代碼,我改變document.write和分配價值document.getElementById("sound").innerHTML

function playSound(soundfile,soundfile1) 
    { 
    document.getElementById("sound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"true\" />"; 
    setTimeout(function(){document.getElementById("sound").innerHTML= '<EMBED src= "' + soundfile1 + '" hidden=true autostart=true loop=false>'},2000); 
    setTimeout(function(){alert("You have successfully launched the MedOrient website! \n Thank you for launching Sri sai medical jobs.");},3000); 
    setTimeout("window.location='http://url'",8000); 
    } 
+0

它仍然不能在Firefox和IE8中工作。你可以看看我的網站[鏈接](http://medorient.com/open.html) – Thiru

+0

請點擊這裏,http://jsfiddle.net/q7VtE/2/。點擊鏈接,你會看到一個提醒,8秒後頁面將被重定向。 –

+0

現在彈出和重定向工作,仍然聲音不工作!幫我 – Thiru