JavaScript:如何确定用户浏览器是否为 Chrome? [英] JavaScript: How to find out if the user browser is Chrome?

查看:44
本文介绍了JavaScript:如何确定用户浏览器是否为 Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些返回布尔值的函数来检查浏览器是否是 Chrome.>

如何创建这样的功能?

解决方案

更新:请参阅 Jonathan 的回答以更新的方式来处理这个问题.下面的答案可能仍然有效,但它可能会在其他浏览器中触发一些误报.

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屋!

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