JavaScript:如何找出用户浏览器是否是Chrome? [英] JavaScript: How to find out if the user browser is Chrome?
本文介绍了JavaScript:如何找出用户浏览器是否是Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些返回布尔值的函数来检查浏览器是否 Chrome 。 p>
如何创建此类功能?
解决方案
请参阅乔纳森的回答,以获取更新的方式来处理此问题。下面的答案可能仍然有效,但它可能会在其他浏览器中引发一些误报。
var isChrome = /Chrome/.test(navigator.userAgent)&& / Google Inc / .test(navigator.vendor);
然而,正如前面提到的,用户代理可能会被欺骗,所以最好使用特征检测(例如 Modernizer )在处理这些问题时,请参考其他答案。
I need some function returning a boolean value to check if the browser is Chrome.
How do I create such functionality?
解决方案
Update: Please see Jonathan's answer for an updated way to handle this. The answer below may still work, but it could likely trigger some false positives in other browsers.
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
However, as mentioned User Agents can be spoofed so it is always best to use feature-detection (e.g. Modernizer) when handling these issues, as other answers mention.
这篇关于JavaScript:如何找出用户浏览器是否是Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文