查找浏览器类型和版本?

任何人都知道使用JavaScript / jQuery找到客户端上安装的浏览器的类型和版本的好方法吗?

看起来jQuery有一些内置函数,但它在检测Chrome时遇到了问题。 这样做还有其他可靠的方法吗?

如果您需要有关访问者使用的浏览器的信息,并将其用于统计信息或向用户显示信息,则可以使用jQuery Browser Plugin 。

它为您提供了一个javascript对象,其中包含有关正在使用的浏览器的所有信息。

当您想要确定浏览器中是否有某个function,应用错误修正等时,请务必进行function检测而不是浏览器检测。

无需重新发明轮子。

方法1:
注意: 从JQuery 1.3开始,不推荐使用jQuery.browser

试试这个 :

       

Browser info: (key : value)


方法2:

// A quick solution without using regexp (to speed up a little). var userAgent = navigator.userAgent.toString().toLowerCase(); if ((userAgent.indexOf('safari') != -1) && !(userAgent.indexOf('chrome') != -1)) { alert('We should be on Safari only!'); }
// A quick solution without using regexp (to speed up a little). var userAgent = navigator.userAgent.toString().toLowerCase(); if ((userAgent.indexOf('safari') != -1) && !(userAgent.indexOf('chrome') != -1)) { alert('We should be on Safari only!'); } 

由于在.jQuery 1.9中删除了$.browser ,请使用:

 // ---------------------------------------------------------- // A short snippet for detecting versions of IE in JavaScript // without resorting to user-agent sniffing // ---------------------------------------------------------- // If you're not in IE (or IE version is less than 5) then: // ie === undefined // If you're in IE (>=5) then you can determine which version: // ie === 7; // IE7 // Thus, to detect IE: // if (ie) {} // And to detect the version: // ie === 6 // IE6 // ie > 7 // IE8, IE9 ... // ie < 9 // Anything less than IE9 // ---------------------------------------------------------- // UPDATE: Now using Live NodeList idea from @jdalton var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '', all[0] ); return v > 4 ? v : undef; }());