无法检测浏览器,我想将其显示为警告(这是http://mozilla.github.com/webrtc-landing/中的一节)
<h3 id="gum" style="color: red; display: none;">
mozGetUserMedia is missing, do you have the latest
<a href="http://nightly.mozilla.org/">Nightly</a> and set
<i>media.navigator.enabled</i> to true?
</h3>
<script>
if (!navigator.webkitGetUserMedia || !navigator.mozGetUserMedia) {
document.getElementById("gum").style.display = "block";}
</script>
这在How can I check webRTC datachannel compatibility using JavaScript in client side?中讨论过但不支持navigator.webkit和moz,我应该怎么做?
答案 0 :(得分:1)
if( !( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia ) ) {
// getUserMedia is not supported
}
改编自Capturing Audio & Video in HTML5。
或
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
if ( !navigator.getUserMedia ) {
// getUserMedia is not supported
}
评论:
var browser = BrowserDetect.browser,
version = parseInt( BrowserDetect.version, 10 );
if ( !( browser == 'Chrome' && version > 25 ||
browser == "Firefox" && version > 18 ) ) {
// do stuff
}
功能检测比浏览器嗅探更可取。