您的位置:首页 > 运维架构

Uncaught TypeError: Cannot read property 'msie' of undefined

2015-07-17 16:39 681 查看

Uncaught TypeError: Cannot read property 'msie' of undefined

因为图方便,抄了别人写的一个jquerry插件,运行时“var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; ”报了Uncaught TypeError: Cannot read property 'msie' of undefined的错误。

网上搜了一下,http://stackoverflow.com/questions/14923301/uncaught-typeerror-cannot-read-property-msie-of-undefined-jquery-tools里面说在jquerry1.9以后,browser属性已经被移除。
上jquerry官网查了一下API,确实已经移除。官网建议使用Modernizr库。
不希望再引入其它库,再上网找其它的解决方案,关键字:jquery1.9浏览器类型。
下面这个是可行的(出处:/article/1781292.html

判断浏览器类型:
$.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) {}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: