本文介绍了如何在客户端使用JavaScript检查webRTC数据通道兼容性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WebRTC数据通道仅每晚在Firefox中工作.如何在客户端检查它?
WebRTC datachannel works only in Firefox nightly. How can I check it in client side?
代码如下所示;
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ffversion>=5)
document.write("You're using FF 5.x or above")
else if (ffversion>=4)
document.write("You're using FF 4.x or above")
else if (ffversion>=3)
document.write("You're using FF 3.x or above")
else if (ffversion>=2)
document.write("You're using FF 2.x")
else if (ffversion>=1)
document.write("You're using FF 1.x")
}
else
document.write("n/a")
推荐答案
您可以简单地测试浏览器当前是否支持要使用的功能.例如:
You can simply test if the browser currently supports the features you're going to use. For example:
if (!window.mozRTCPeerConnection)
// error, browser doesn't support it
如果您有兴趣,请阅读以下有趣的文章: Hello Chrome,它是Firefox打电话!
If you're interested, here an interesting article: Hello Chrome, it’s Firefox calling!
基本上,您只需使用 webkit
前缀而不是 moz
,就可以在Chrome中实现相同的功能.
You basically can implement the same feature in Chrome just using webkit
prefix instead of moz
.
这篇关于如何在客户端使用JavaScript检查webRTC数据通道兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!