浏览器cannot read property 'msie' of undefined的解决方法

时间:2022-12-01 23:48:30

练习demo,版本升级很容易有错误…,百度和Google

Uncaught TypeError: Cannot read property 'msie' of undefined

谷歌:

jQuery.browser() removed

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin. We recommend using feature detection with a library such as Modernizr.

意思就是jQuery.browser()在后版本不支持了,需要引入一个js插件来进行兼容处理;好吧,在引入一个js文件就可以了:
下载地址:
jquery-migrate-1.3.0.js

下载这个js文件,然后放在jquery文件下面:

  <script src="jquery-2.1.4.js"></script>
<script src="jquery-migrate-1.3.0.js"></script>

原文链接


如以上无效,请参考以下链接:
Uncaught TypeError: Cannot read property ‘msie’ of undefined - jQuery tools

//在代码中加上
<script type="text/javascript">
jQuery.browser = {};
(function () {
jQuery.browser.msie = false;
jQuery.browser.version = 0;
if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
jQuery.browser.msie = true;
jQuery.browser.version = RegExp.$1;
}
})();
</script>