javascript - 怎么判断是否不是chrome浏览器
迷茫
迷茫 2017-04-11 12:56:14
[JavaScript讨论组]

window.navigator.userAgent.indexOf('Chrome') == -1

看到网上是这么判断的。 但是发现这会有问题。 edge 都判断是chrome

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(4)
高洛峰

navigator.userAgent:

IE7:"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
IE8:"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"
IE9:"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
IE10:"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"
Edge:"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; GWX:RESERVED; rv:11.0) like Gecko"
Firefox:"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0"
Chrome:"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"

所以:

if(navigator.userAgent.indexOf("Chrome") > -1){
    // 即是chrome
}
高洛峰

你这个是,不是Chrome浏览器的意思吧。。。

巴扎黑

navigator.userAgent会输出浏览器信息,然后根据信息自己做判断吧

巴扎黑

不大好判断,,navigator.userAgent.toLowerCase().indexOf('chrome') 这个方式也可以得出 遨游浏览器 safari浏览器

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号