Home > Article > Web Front-end > Use javascript to determine browser type
This article mainly introduces the use of javascript to determine the browser type, which has certain reference value. Now I share it with you. Friends in need can refer to it
Related methods to determine the browsing type
window.navigator.userAgent.toLowerCase()//将浏览器信息获取,并转成小写
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()
The above code can judge IE, Firefox, and Google Chrome, but domestic QQ browsing When Sogou Browser is running, the alert result is "Chrome Browser"
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 Browse The browser cannot detect that it is a 360 browser through the above method
//application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360 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("搜狗浏览器") } 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()
In this way, it can be determined that it is a 360 browser
The above is the entire content of this article, I hope it will help everyone learn Helpful, please pay attention to the PHP Chinese website for more related content!
Related recommendations:
JS browser event loop mechanism
Use Node to process file uploads
The above is the detailed content of Use javascript to determine browser type. For more information, please follow other related articles on the PHP Chinese website!