欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

TypeError: $.browser is undefined

shiping1 的头像
Use navigation.userAgent
if(navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0){
    alert("IE")
}

Use this snippet:

var isIE = navigator.userAgent.toUpperCase().indexOf('MSIE') >=0 ? 'click' : 'change' ;

jQuery("input[name^='cat']").bind(isIE , function(event) {   
    var id = jQuery(this).attr('id');
    mantener_seleccion(id);//its a function name
});

来自 http://stackoverflow.com/questions/24379212/typeerror-jquery-browser-is-undefined

jQuery 1.9 移除了 $.browser 的替代方法
j
Query 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合使用 jQuery 1.9 和 2.0, 官方的解决方案是:

<!--[if lt IE 9]>
    <script src='jquery-1.9.0.js'></script>
<![endif]-->
<!--[if gte IE 9]>
    <script src='jquery-2.0.0.js'></script>
<![endif]-->

从长久来看,这样有利于在复杂情况下根据浏览器特性进行分别处理, 而不是简单的检测浏览器类型和版本。 但目前很多旧程序的移植恐怕无法直接过渡为根据浏览器支持特性, 所以在网上找了一些能够直接替换的解决办法。

判断浏览器类型:

$.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());

等号后面的表达式返回的就是 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) {}

终极方法是用另外的类库替代,比如 这个 , 但作者也不推荐使用浏览器类型和版本来进行判断。

来自 http://www.fwolf.com/blog/post/35


 

Browser detect

A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give specific instructions or load a new page in case the viewer uses, for instance, Safari.

If you're new to JavaScript, don't use browser detects. You don’t need them. Please read the object detection page first.

Use WhichBrowser

This page used to contain my own browser detect script, but I found that I do not have enough time to keep it up to date. Therefore I removed it.

I advise you to use WhichBrowser. It’s up-to-date, and contains a treasure trove of mobile information.

If you use my old script I advise you to switch to WhichBrowser.

navigator

Below you see the objects contained by the object navigator. These variables can be read out and give information about the browser and computer of your users.

 

navigator.vendorSub = 
navigator.productSub = 20030107
navigator.vendor = Google Inc.
navigator.maxTouchPoints = 0
navigator.hardwareConcurrency = 2
navigator.appCodeName = Mozilla
navigator.appName = Netscape
navigator.appVersion = 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.8 Safari/537.36
navigator.platform = Win32
navigator.product = Gecko
navigator.userAgent = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.8 Safari/537.36
navigator.language = zh-CN
navigator.languages = zh-CN,zh
navigator.onLine = true
navigator.cookieEnabled = true
navigator.getStorageUpdates = function getStorageUpdates() { [native code] }
navigator.doNotTrack = null
navigator.geolocation = [object Geolocation]
navigator.plugins = [object PluginArray]
navigator.mimeTypes = [object MimeTypeArray]
navigator.webkitTemporaryStorage = [object DeprecatedStorageQuota]
navigator.webkitPersistentStorage = [object DeprecatedStorageQuota]
navigator.serviceWorker = [object ServiceWorkerContainer]
navigator.getBattery = function getBattery() { [native code] }
navigator.sendBeacon = function sendBeacon() { [native code] }
navigator.getGamepads = function getGamepads() { [native code] }
navigator.webkitGetUserMedia = function webkitGetUserMedia() { [native code] }
navigator.javaEnabled = function javaEnabled() { [native code] }
navigator.vibrate = function vibrate() { [native code] }
navigator.requestMIDIAccess = function requestMIDIAccess() { [native code] }
navigator.mediaDevices = [object MediaDevices]
navigator.permissions = [object Permissions]
navigator.presentation = [object Presentation]
navigator.requestMediaKeySystemAccess = function requestMediaKeySystemAccess() { [native code] }
navigator.registerProtocolHandler = function registerProtocolHandler() { [native code] }
navigator.unregisterProtocolHandler = function unregisterProtocolHandler() { [native code] }


来自  http://www.quirksmode.org/js/detect.html

普通分类: