什么把戏会给最可靠/兼容报警声在大多数浏览器在浏览器窗口 [英] What trick will give most reliable/compatible sound alarm in a browser window for most browsers

查看:158
本文介绍了什么把戏会给最可靠/兼容报警声在大多数浏览器在浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在浏览器窗口中,preferably与任何浏览器插件的要求(使用Quicktime /闪存)播放使用Javascript发出报警声。我一直在尝试与标签及JavaScript中的新的音频对象,但结果是喜忧参半:

I want to be able to play an alarm sound using Javascript in a browser window, preferably with the requirement for any browser plugins (Quicktime/Flash). I have been experimenting with the tag and the new Audio object in Javascript, but results are mixed:

正如你所看到的,有没有变种,在所有浏览器上运行。

As you can see, there is no variant that works on all browsers.

我错过一招是更跨浏览器兼容?

Do I miss a trick that is more cross-browser compatible?

这是我的code:

// mp3 with Audio object
var snd = new Audio("/sounds/beep.mp3");snd.play();

// wav with Audio object
var snd = new Audio("/sounds/beep.wav");snd.play();

// mp3 with EMBED tag
$("#alarmsound").empty().append
('<embed src="/sounds/beep.mp3" autostart="true" loop="false" '+
 'volume="100" hidden="true" width="1" height="1" />');

// wav with EMBED tag
$("#alarmsound").empty().append
('<embed src="/sounds/beep.wav" autostart="true" loop="false" '+
 'volume="100" hidden="true" width="1" height="1" />');

}

推荐答案

感谢您为表。我有同样的问题。我不希望使用任何闪光灯,但它必须在任何平台上运行。 HTML 5仅由较新的浏览器支持的,并且不能被用作一个世界广泛的解决方案。仍然有太多人使用IE 6 :-)
我用jQuery的浏览器属性来管理不同的对象:

Thank you for the table. I have the same problem. I don't want to use any flash, but it has to work on any platform. HTML 5 is only supported by newer Browsers and can't be used as a 'world wide' solution. There are still too many People using IE 6 :-) I used jQuery's browser property to manage the different objects:

if ($.browser.mozilla || $.browser.opera) {
  var snd = new Audio("beep.wav"); snd.play();
...
if ($.browser.msie) {
  var soundPlayer = $("<embed src='scripts/beep.mp3' hidden='true' autostart='true' loop='false' />");
  $("body").append(soundPlayer);
...

这篇关于什么把戏会给最可靠/兼容报警声在大多数浏览器在浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆