Detailed description of IE's conditional comments and Determination of IE versions (with instance code) _ javascript skills

Source: Internet
Author: User
Conditional annotations of IE are proprietary (and therefore non-standard) Miscrosoft extensions for regular (X) HTML annotations. As the name suggests, conditional comments allow you to display code blocks (not necessarily css, html code, or even JavaScript code) based on conditions (such as the browser version ). Conditional annotations of IE are proprietary (and therefore non-standard) Miscrosoft extensions for regular (X) HTML annotations. As the name suggests, conditional comments allow you to display code blocks based on conditions (such as the browser version. Although not standard, conditional comments appear as regular comments for all other browsers, so they are essentially harmless. Conditional comments appear for the first time in IE5 on Windows and are supported by all subsequent versions of the Widnows browser.

Conditional annotations and their validity of IE are easy to remember. The main drawback is that these annotations need to be placed on HTML pages rather than CSS pages. In this way, when you don't need these things or make some changes, you need to maintain a lot of things.

Let's take a look at several examples --

Only IE can recognize
Only IE5 and later versions support IE conditional comments. All "only IE" means "only IE5 and later.

The Code is as follows:




Only specific versions can be identified
For example, only IE5 can be identified, only IE6 can be identified, and only IE7 or IE8 can be identified. The recognition condition is a specific version, which is neither high nor low. For example, the following code block will only be valid in IE8.

The Code is as follows:





Only versions that are not specific can be identified.
Of course, the IE browser must be in version 5 or above to be discussed. For example, in the following example, IE7 is not recognizable.

The Code is as follows:





Only later than a specific version can be identified
A code block that can be recognized by a later version of IE.

The Code is as follows:





Some may ask why IE7 has not been applied? That is because IE7 is equal to IE7, not higher than IE7. All ie7.

Equal to or higher than a specific version.

The Code is as follows:





Only versions earlier than the specified version can be identified.

The Code is as follows:





Only versions equal to or earlier than a specific version can be identified.

The Code is as follows:





Keyword explanation
The code above seems hard to remember. In fact, it is easy to remember to explain the keywords a little.
Lt: Short for Less than, that is, Less.
Lte: Short for Less than or equal to, that is, Less than or equal.
Gt: Short for Greater than, that is, Greater.
Gte: Short for Greater than or equal to, that is, Greater than or equal.
! : It means not equal, which is the same as the non-equal identifier in javascript.
This explains whether it is easy to remember more.
Special notes on IE condition annotations
Only IE can recognize it --
I once saw the following code, and now I can't help but smile. What is the significance of such code?

The Code is as follows:




It's not just CSS.
For a long time, I had a misunderstanding-I thought it was used to load different css based on different browsers to solve style compatibility problems. Actually, I am wrong. It can actually do more. It can protect any code block-HTML code block, JavaScript code block, server code ...... Take a look at the following code.

The Code is as follows:


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.