Conditional comments are a mechanism by which the author of a web page can use non-standard features of some browsers , avoiding incompatibility issues with other browsers.
Currently, conditional comments can be used to write custom code for Internet Explorer . In the following way, for example, you can enable special CSS rules for this browser:
<! - [if IE]> <link rel = "stylesheet" type = "text / css" href = "ie.css"> <! [endif] ->
It is possible to specify a separate browser version. This may come in handy to achieve compatibility with older versions of the browser that do not support the standard model:
<! - Enabling styles for Internet Explorer 5 ->
<! - [if IE 5]> <link rel = "stylesheet" type = "text / css" href = "ie5.css"> <! [endif] ->
<! - Enabling styles for Internet Explorer less than version 6 ->
<! - [if lt IE 6]> <link rel = "stylesheet" type = "text / css" href = "ie6.css"> <! [endif] ->
JScript Conditional Comments
Another type of conditional commentary, which also applies only to Internet Explorer browsers, is comments added to the JScript program code, for example:
if ( / * @ cc_on! @ * / false ) {
// code specific for Internet Explorer version ≤ 10
}
This construction works because, after conditional comments are expanded, the mentioned browser versions will see an if( ! false )
check, which will give a true result; other browsers will perceive comments as ordinary unexecutable fragments of the program, and will receive if( false )
.