这篇文章主要介绍了关于利用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浏览器
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
js浏览器事件循环机制
用node处理文件上传
以上就是利用javascript判断浏览器类型的详细内容。