IE's conditional annotation determines IE version detailed (with instance code) _javascript skills

Source: Internet
Author: User
The conditional annotation of IE is a proprietary (and therefore nonstandard), Miscrosoft extension of the general (X) HTML annotation. As the name suggests, conditional annotations enable you to display code blocks based on criteria such as browser versions. Although nonstandard, conditional annotations appear as regular comments for all other browsers, so they are inherently harmless. Conditional annotations appear for the first time in IE5 on Windows and are supported by all subsequent versions of the Widnows browser.

The conditional annotation of IE is valid, and it is very easy to remember. The main drawback is that these annotations need to be placed in HTML pages rather than in CSS. This way, you need to maintain a lot of places when you don't need these things, or when you change them.

Let's take a look at a few examples--

only IE can recognize
Because only IE5 above version to support IE conditional annotation, all "only ie" to recognize the meaning is "only IE5 version above" to recognize.
Copy Code code as follows:

<!--[If ie]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->

only specific versions can recognize
For example, only IE5 can recognize, only IE6 can recognize, only IE7 or IE8 can recognize. The condition of recognition is a specific version, either High or low. For example, the following code block will only be valid in IE8
Copy Code code as follows:

<!--[if IE 8]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


only not a specific version of the ability to recognize
Of course, ie browser needs more than 5 version, only in the discussion scope. For example, in the following example, a specific IE7 version is not recognized.
Copy Code code as follows:

<!--[if! IE 7]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


only higher than a specific version to recognize
Only blocks of code that are higher than the developed version of IE browsers can recognize.
Copy Code code as follows:

<!--[if GT IE 7]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


Some friends will ask, why IE7 not apply to the effect? That's because IE7 equals IE7, not higher than IE7. All IE7 also had no effect.

equal to or higher than a specific version to recognize
Copy Code code as follows:

<!--[if GTE IE 7]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


only below a specific version of the ability to identify
Copy Code code as follows:

<!--[If Lt IE 7]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


equal to or less than a specific version of the ability to recognize
Copy Code code as follows:

<!--[If LTE IE 7]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->


keyword explanation
The above code seems very difficult to remember, in fact, just a little bit to explain the keyword is easy to remember.
LT: It is the shorthand for less than, which means less than.
LTE: Is the shorthand for less than or equal to, meaning less than or equal to.
GT: is the shorthand for greater than, which means greater than.
GTE: is the shorthand for greater than or equal to, which is greater than or equal to the meaning.
!: is not equal to the meaning, and JavaScript is not equal to the same judge character.
This explains, is not good to remember much.
Special notes on IE condition annotations
Only IE can recognize oh--
Once saw the following code, now think of it can not help but a little want to laugh. What is the point of such a code?
Copy Code code as follows:

<!--[if! Ie]>
<style type= "Text/css" >
@import "Test.css";
</style>
<! [endif]-->

not just css OH
For a long time, I had a misconception that it was used to address style compatibility problems by loading different CSS into different browsers. In fact, I was wrong. It can actually do more. It can protect any code block--html code block, JavaScript code block, server-side code ... Look at the code below.
Copy Code code as follows:

<!--[If ie]>
You are using IE browser, you will also pop-up box OH.
<script type= "Text/javascript" > Alert ("You are using IE browser!") ");</script>
<! [endif]-->

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.