Using JS framework jquery to determine IE browser version to resolve browser compatibility issues

Source: Internet
Author: User
Tags min versions

IE really let the designer hate the tooth itch thing, and now has IE6, IE7, IE8, IE9, IE10 this five different versions of the browser, and there are a small difference. But there is no way to make the page appear in every browser as well as to accommodate it.

But now I am basically not willing to be compatible with the lower version of IE. such as IE6, IE7 these direct ignore! IE8 's words will do. Fortunately, IE9 and IE10 on the network standard support are compared, such as IE9 version of the browser after the popularization of good very good.

But do not do compatibility is not compatible, or to be simple to deal with. Luckily, JQuery provides a browser tag that allows us to determine what browsers and versions the current visitor is using:

<script type= "Text/javascript" src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" ></ Script>
<script type= "Text/javascript" >
$ (function () {
var useragent = Window.navigator.userAgent.toLowerCase ();
var version = $.browser.version;
$ (". Info"). HTML (
"");
});
</script>

<body>
<div class= "Info" ></div>
</body>

I used a few simple examples to show the current browser useragent and JQuery.browser.version, and then in the IE 6~8 test, but the result of the display is really let out of amazement!

From the results, IE 7 is wrong to judge, in a careful look at its useragent will find that inside in addition to MSIE 7.0, but also contains a MSIE 6.0, so jQuery.browser.version than the right to have a problem. Now that we know the problem, we can solve the problem.

The first way is a more direct way, first to determine if there is a higher version of UserAgent, that is based on the main version:

When you want to use it, you can use $.BROWSER.MSIE6~10 to do the judgment processing. The other is to directly modify the JQuery.browser.version of the method:

 <script type= "Text/javascript" src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" > </script> <script type= "Text/javascript" > $ (function () {var useragent = Window.navigator.userAgent.toLowe
 
		Rcase ();
		$.browser.msie10 = $.browser.msie &&/msie 10.0/i.test (useragent); 
		$.BROWSER.MSIE9 = $.browser.msie &&/msie 9.0/i.test (useragent);
		$.BROWSER.MSIE8 = $.browser.msie &&/msie 8.0/i.test (useragent);
$.browser.msie7 = $.browser.msie &&/msie 7.0/i.test (useragent); $.browser.msie6 =!$.browser.msie8 &&!$.browser.msie7 && $.browser.msie &&/msie 6.0/i.test (
 
		useragent);  $ (". Info"). HTML ("

After such a correction, when we use jQuery.browser.version to judge the correct display of IE version number. Both ways have their convenience, it depends on how you choose to use it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.