-1

我使用以下脚本在延时后播放 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
4

1 回答 1

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);
  }
于 2012-11-10T14:56:46.723 回答