解決 $.browser 被 remove 的問題

摘要:解決 $.browser 被 remove 的問題

在 JQuery 1.9 版本裡 , 已經移除了有關瀏覽器判斷的 function : $.browser , 

Contains flags for the useragent, read from navigator.userAgentThis property was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

 

因為其判斷已經不能適用於目前最新的 IE  瀏覽器 , 之前是以瀏覽器標頭是否帶著

 

MSIE 字串來判斷 , 而如今在 IE 11 其標頭目前是以 mozilla  字串來代替了 .. 

 

也因此 $.browser 也已經沒有作用了 .

 

那之後我們要如何來判斷瀏覽器的類型呢 ?

 

在 IE 11 中我們可以使用其標頭中的 trident 來判斷  ,  因此要判斷最新的 IE 和舊版的 IE 就可以使用下面的方式來判斷

 


if (navigator.userAgent.match(/msie|trident/i)){        
           alert('I am an old fashioned Internet Explorer');      
}   

 

 

參考資料 : 

Easiest/Lightest Replacement For Browser Detection jQuery 1.9?