这篇文章主要介绍了关于利用javascript判断浏览器类型,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
判断浏览类型的相关方法
控制台打印浏览器相关信息
window.navigator.userAgent.toLowerCase()//将浏览器信息获取,并转成小写
登录后复制
判断是ie、火狐、chrome浏览器
function isBrowser(){ var agent=navigator.userAgent.toLowerCase() console.log(agent) if(agent.indexOf('chrome')>0){ alert("chrome浏览器") } if(agent.indexOf('firefox')>0){ alert("firefox浏览器") } if(agent.indexOf('trident')>0){ alert("IE浏览器") } } isBrowser()
登录后复制
上面代码可以判断ie,火狐,谷歌浏览器,但是 国内的QQ浏览器,搜狗浏览器运行的时候alert的结果是”Chrome浏览器”
在判断是qq还是Chrome浏览器
function isBrowser(){ var agent=navigator.userAgent.toLowerCase() console.log(agent) System=function(){ if(agent.indexOf('qqbrowser')>0){//判断是qq浏览器还是其它浏览器 return alert("qq浏览器") } if(agent.indexOf("se 2.x")>0){ return alert("搜狗浏览器") } alert('chrome浏览器') } System() if(agent.indexOf('firefox')>0){ alert("firefox浏览器") } if(agent.indexOf('trident')>0){ alert("IE浏览器") } } isBrowser()
登录后复制
360浏览器奇葩
360浏览器通过上面的方法并不能检测出是360浏览器
//application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360function isBrowser(){ var agent=navigator.userAgent.toLowerCase() console.log(agent) System=function(){ if(agent.indexOf('qqbrowser')>0){//判断是qq浏览器还是其它浏览器 return alert("qq浏览器") } if(agent.indexOf("se 2.x")>0){ return alert("搜狗浏览器") } var is360 = _mime("type", "application/vnd.chromium.remoting-viewer"); if (is360) { return "360浏览器" } //检测是否是谷歌内核(可排除360及谷歌以外的浏览器) //测试mime function _mime(option, value) { var mimeTypes = navigator.mimeTypes; console.log(mimeTypes) for (var mt in mimeTypes) { if (mimeTypes[mt][option] == value) { return true; } } return false; } alert('chrome浏览器') } System() if(agent.indexOf('firefox')>0){ alert("firefox浏览器") } if(agent.indexOf('trident')>0){ alert("IE浏览器") } } isBrowser()
登录后复制
这样就可以判断出是360浏览器
立即学习“Java免费学习笔记(深入)”;
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
JS浏览器事件循环机制
用Node处理文件上传
以上就是利用javascript判断浏览器类型的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2746976.html