如何使用jQuery或JavaScript获取浏览器名称?

如何使用jQuery或JavaScript获取浏览器名称?

问题描述:

我想要得到我使用的浏览器的名称。目前我正在尝试'navigator.userAgent',但它显示'铬'为边缘和铬浏览器。如何使用jQuery或JavaScript获取浏览器名称?

+0

**你可以找到这个解决方案** [链接](http://*.com/questions/36547312/get-current-browser-name-using-jquery-code) –

这是工作,我也用它。它将完美展现浏览器名称。这里是demo

var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; 
    // Firefox 1.0+ 
var isFirefox = typeof InstallTrigger !== 'undefined'; 
    // At least Safari 3+: "[object HTMLElementConstructor]" 
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; 
    // Internet Explorer 6-11 
var isIE = /*@[email protected]*/false || !!document.documentMode; 
    // Edge 20+ 
var isEdge = !isIE && !!window.StyleMedia; 
    // Chrome 1+ 
var isChrome = !!window.chrome && !!window.chrome.webstore; 
    // Blink engine detection 
var isBlink = (isChrome || isOpera) && !!window.CSS; 
+0

曾任职对我也是。感谢很多。 –

最好的方法是检测是jquery-migrate最小和测试,其目的是解决任何兼容性代码使用jQuery Migrate 3.0并升级到jQuery 3.0之前的问题。

if($.browser.mozilla) { 

} 
else if($.browser.chrome) { 

} 
... go on