JS to determine whether IE
The code is as follows |
Copy Code |
function Ismsie () { var match =/(MSIE) ([w.] +)/.exec (Navigator.userAgent.toLowerCase ()); if (match!== null) { return true; }else{ return false; } } |
From the Jquery.browser of jquery, jquery scrapped this method from 1.9, using Jquery.support to detect browser-supported features.
code is as follows |
copy code |
<script type=" Text/javascript "src=" Jquery-1.3.2.min.js "></script" <script> $ (function () { if ($.browser.msie) { alert ("This is an IE browser"); }else if ($.browser.opera) { alert (" This is an opera browser "); }else if ($.browser.mozilla) { alert (" This is a Firefox browser "); }else if ($.browser.safari) { alert (" This is a Safari browser "); } }) </script> |
When the page is loaded to determine the type of browser, the types that can be judged are MSIE, Mozilla, Opera, Safari
jquery says that the use of navigator.useragent detection is inaccurate and is susceptible to forgery and deception.
JQuery starts with the 1.9 version, removing $.browser and $.browser.version, and substituting $.support. In the newer version 2.0, IE 6/7/8 will no longer be supported. Later, if the user needs to support IE 6/7/8, only jQuery 1.9 can be used. If you want to fully support IE and mix jQuery 1.9 and 2.0, the official solution is:
The code is as follows |
Copy Code |
<!--[If Lt IE 9]> <script src= ' jquery-1.9.0.js ' ></script> <! [endif]--> <!--[if GTE IE 9]> <script src= ' jquery-2.0.0.js ' ></script> <! [endif]--> |
In the long run, this helps to deal with the browser's characteristics separately in complex situations, rather than simply detecting browser types and versions. However, many of the old program porting may not be directly to the browser support features, so on the Internet to find a number of direct replacement solutions.
To determine the browser type:
The code is as follows |
Copy Code |
$.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 ()); |
The expression following the equal sign returns the True/false, which can be used directly to replace the original $.browser.msie, and so on.
Check for IE6:
The code is as follows |
Copy Code |
Old if ($.browser.msie && 7 > $.browser.version) {} New if (' undefined ' = = typeof (Document.body.style.maxHeight)) {} |
Check for IE 6-8:
The code is as follows |
Copy Code |
if (!$.support.leadingwhitespace) {} |
The ultimate approach is to substitute a different class library, such as this, but the author does not recommend using browser type and version to judge.
But I still think, this thing is low cost, very valuable. As for the developers to forge it, let them forge it, I just used to do a more violent demotion processing.