我使用以下脚本在延迟时间后播放2个声音文件
<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
答案 0 :(得分: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);
}