WebRTC 数据通道只能在 Firefox nightly 中运行。我如何在客户端检查它?
代码如下;
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")
最佳答案
您可以简单地测试浏览器当前是否支持您将要使用的功能。例如:
if (!window.mozRTCPeerConnection)
// error, browser doesn't support it
如果您有兴趣,这里有一篇有趣的文章:Hello Chrome, it’s Firefox calling!
您基本上可以在 Chrome 中实现相同的功能,只需使用 webkit
前缀而不是 moz
。
关于javascript - 如何在客户端使用 JavaScript 检查 webRTC 数据通道兼容性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774386/