1. 程式人生 > >瀏覽器cannot read property 'msie' of undefined的解決方法

瀏覽器cannot read property 'msie' of undefined的解決方法

                     

   想起以前看到的一個笑話:一個懸崖邊上立著個”Warnning”的牌子,懸崖下躺滿了程式設計師。    對於Warnning如果要求不高通常可以忽略,對於瀏覽器報錯真的要注意一下了,否則程式執行不起來啊→_→    練習demo的時候無論怎麼選擇js版本還是簡化文件內容都無法達到預期效果,於是呼叫”F12”大法,好吧,看到這麼一個錯誤:    

Uncaught TypeError: Cannot read property 'msie' of undefined
  • 1

谷歌之:

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檔案就可以了:

下載地址:

下載這個js檔案,然後放在jquery檔案下面:

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

然後瀏覽器的”Error”變成了”Warnning”,哼!程式設計師怎麼會在意這個呢,能執行就OK了。

(後話,將來的某一天我就躺在了”Warnning”懸崖下 TnT )