2013-12-19 73 views

回答

0

警告框播放声音取决于浏览器和操作系统设置。所以,你不能依赖那个。

但是,你可以使用JavaScript来播放声音这样

<script language="javascript" type="text/javascript"> 
function playSound(soundfile) { 
    document.getElementById("dummy").innerHTML= 
     "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" 
      loop=\"false\" />"; 
} 
</script> 

注:和你的HTML应该有id为dummy的元素。

现在,只要你想播放一些声音,你就可以调用playSound

来源:http://webdesign.about.com/od/sound/a/play_sound_oncl.htm

由于@bigblind建议,您可以使用HTML 5 based sound玩选项,以及。

+1

不需要ro嵌入,我们现在在现代浏览器中使用HTML5音频,并且有闪回回退。 – bigblind

+0

@bigblind酷。请检查我的更新回答:) – thefourtheye

+0

有一个关于在HTML5rocks http://www.html5rocks.com/en/tutorials/webaudio/intro/上使用它的真棒教程。我正在写一个基于此的答案,但我认为阅读实际的教程将比阅读缩短的版本更有用,因为它包含许多重要细节。 – bigblind

相关问题