visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Web :: Browser issues :: Knowledge Base : how to include patching code for Internet Explorer only


By: VGR France  Date: 02/05/2006 10:07:06  English  Points: 0 Status: Answered
Quality : Excellent
This is about the "conditional comments" introduced in Internet Explorer 5.0 Windows, quite a long time ago.

This technique is not widely used, but can prove itself valuable in that :
- you don't have to code server-side a browser detection/sniffing routine and include yourself the "IE patching" CSS style sheet or javascript code (like for bringing back transparency to PNG images...)
- you just generate HTML code ready for all browsers (the standards compliant ones plus Internet Exploder) and you let the Redmond "browser" execute its conditional code, a bit like the conditional compilation [comments] of Turbo-Pascal/Delphi with IFDEF...ENDIF

Here we go :

The simpliest form is a block like this :

<!--[if IE]> anything here will be treated as an HTML comment by real (non-IE) browsers but will be executed (rendered) by Internet Explorer, like the classical : <link rel="stylesheet" href="style/ie.css" type="text/css" /> <![endif]-->



The more general form is :

<!--[if ( ! )* ( comparison )* IE ( version number )* ]> HTML content to parse if the condition is true goes here <![endif]-->



Where the comparison is any one of the 4 comparison operators: lt (less than), lte (less than or equal to), gt (greater than), or gte (greater than or equal to). Note that, if you use any of the comparison operators, you must specify a version number. If a comparison operator is left out, equality is assumed and a version number is not needed.

The version number is any valid integer or floating point browser version number (though the only valid values right now are 5, 5.5000, and 6).

Browser Support / Behaviour
Applied By
* Win IE 5.0 - 6.x
Not Applied By
* All Mozilla 0.6 - 1.6
* Win IE 4.0
* OSX IE 5.x
* Mac IE 4.0 - 5.x
* All NS 4.x
* Win Opera 3.5 - 7.x
* OSX/Mac Opera 5.0 - 6.0
* OSX Safari 1.x
* MSN for OSX
* OSX iCab 2.x
* OSX OmniWeb 4.0 - 4.2
* Konqueror

Post-Scriptum :
***If you agree to not validate your HTML output*** you may use what is called "the downlevel-revealed form" of conditional comment which allows non IE5 Windows browsers to view the commented HTML (which would be helpful in hiding CSS from IE5+ Windows but not from other browsers). This is invalid but may be useful to know anyway, as it works :

<![if IE]> ... <![endif]>



PPS : the Microsoft documentation about those conditional comments is here on MSDN

Do register to be able to answer

EContact
browser fav
page generated in 330.394030 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page