获取判断IE版本 TypeError: Cannot read property 'msie' of undefined
Posted helloworld6379
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取判断IE版本 TypeError: Cannot read property 'msie' of undefined相关的知识,希望对你有一定的参考价值。
注意:一下方法只适用于IE11 以下:
TypeError: Cannot read property ‘msie‘ of undefined
jquery1.9去掉了 $.browser 所以报错 官方说明 : https://api.jquery.com/jQuery.browser/
1 大佬的贴: https://stackoverflow.com/questions/14892095/browser-msie-error-after-update-to-jquery-1-9-1
/** * Returns the version of Internet Explorer or a -1 * (indicating the use of another browser). */ function getInternetExplorerVersion() var rv = -1; // Return value assumes failure. if (navigator.appName == ‘Microsoft Internet Explorer‘) var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]1,[\.0-9]0,)"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); return rv; function checkVersion() var msg = "You‘re not using Internet Explorer."; var ver = getInternetExplorerVersion(); if ( ver > -1 ) if ( ver >= 8.0 ) msg = "You‘re using a recent copy of Internet Explorer." else msg = "You should upgrade your copy of Internet Explorer."; alert( msg );
2:
// ---------------------------------------------------------- // 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 = ‘<!--[if gt IE ‘ + (++v) + ‘]><i></i><![endif]-->‘, all[0] ); return v > 4 ? v : undef; ());
3
if (navigator.userAgent.toLowerCase().indexOf(‘msie 6‘) != -1)
6为你要测试的版本号
以上是关于获取判断IE版本 TypeError: Cannot read property 'msie' of undefined的主要内容,如果未能解决你的问题,请参考以下文章
[完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器
一个小功能从js判断ie版本,浅谈navigator对象的appName属性
TypeError:更新后无法读取未定义的属性“_attributes”