首页 > 代码库 > jQuery 1.9不支持$.browser 怎么判断浏览器类型和版本

jQuery 1.9不支持$.browser 怎么判断浏览器类型和版本

$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());
$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());

$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
 
或者
$.browser.mozilla = /firefox/i.test(navigator.userAgent);
$.browser.webkit = /webkit/i.test(navigator.userAgent);
$.browser.opera = /opera/i.test(navigator.userAgent);
$.browser.msie = /msie/i.test(navigator.userAgent);
 
?

等号后面的表达式返回的就是 true/false, 可以直接用来替换原来的$.browser.msie等。

检查是否为 IE6
// Old
if ($.browser.msie && 7  $.browser.version) {}
// New
if (‘undefined‘ == typeof(document.body.style.maxHeight)) {}

检查是否为 IE 6-8

if (!$.support.leadingWhitespace) {}

navigator.geolocation = [object Geolocation]
navigator.webkitPersistentStorage = [object StorageQuota]
navigator.webkitTemporaryStorage = [object StorageQuota]
navigator.doNotTrack = 1
navigator.onLine = true
navigator.product = Gecko
navigator.appCodeName = Mozilla
navigator.userAgent = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
navigator.platform = Win32
navigator.appVersion = 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
navigator.appName = Netscape
navigator.vendorSub = 
navigator.vendor = Google Inc.
navigator.productSub = 20030107
navigator.cookieEnabled = true
navigator.mimeTypes = [object MimeTypeArray]
navigator.plugins = [object PluginArray]
navigator.language = zh-CN
navigator.javaEnabled = function javaEnabled() { [native code] }
navigator.getStorageUpdates = function getStorageUpdates() { [native code] }
navigator.registerProtocolHandler = function registerProtocolHandler() { [native code] }
navigator.webkitGetGamepads = function webkitGetGamepads() { [native code] }
navigator.webkitGetUserMedia = function webkitGetUserMedia() { [native code] }
navigator.vibrate = function vibrate() { [native code] }