If IE IE conditions do not work

I force myself nuts, trying to make comment conditions work, and I'm out of luck, can someone explain what I'm doing wrong?

Here is my code:

<!--[if IE 10]> IE IS VERSION 10<br /> <![endif]--> <!--[if !IE]><!--> Browser is not IE <!--<![endif]--> <!--[if lt IE 9]> IE IS LESS THAN VERSION 9<br /> <![endif]--> 

What happens is disappointing. When I load the page with the above code in IE8 , it receives the message "IE LESS THAN VERSION 9" . Good? No, because when I load SAME PAGE in IE10 , I get the message "The browser is not IE"

Why does he think IE10 is not an IE browser ?! I was browsing page by page, but there seems to be something wrong with my code due to what I found.

+16
html comments internet-explorer conditional
Oct 21 '13 at 18:30
source share
5 answers

IE 10 does not support conditional statements.

Conditional statements in Internet Explorer 10 .. It will treat conditional comments as regular HTML comments and be completely ignored.

Instead of detecting a browser, use a feature detection library such as Modernizr .

found a solution on impressivewebs in this comment :

Here is a demo

Decision:

 if (Function('/*@cc_on return document.documentMode===10@*/')()) { alert('IE 10'); } else { alert('Not IE 10'); } 

it

  • does not require conditional comments;
  • works even when compressing / processing comments;
  • no ie10 class added in Internet Explorer 11;
  • more likely to work in accordance with the idea of โ€‹โ€‹Internet Explorer 11, working in Internet Explorer 10 compatibility mode;
  • no stand-alone script tag needed (may be added to other JavaScript code in the head).
  • no jQuery required for testing
+14
Oct 21 '13 at 18:35
source share

I am surprised that no one added a single solution to css. If you just want to use css, use an instruction like:

 @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { /* Put your IE-only styles here. Works for IS 10 & IE 11*/ } 

This way you don't have to rely on jquery or any html markup. Just post it to css and you're good to go.

Now, is it a hack? Probably. It depends on using a high contrast microsoft tag, but since no other browser uses the ms tag, you should be good to go.

Finally, browse these pages for more information:

Blog post

MS website on contrast tag

+13
Dec 15 '16 at 16:49
source share

IE 10 rejected conditional comments.

In javascript you can do something like this:

 if ($.browser.msie && $.browser.version === 10) { // stuff here (like adding an IE10 class to the body or html tag } 
+2
Oct 21 '13 at 18:33
source share

IE 10, 11 and up no longer support conditional comments.

See this answer: stack overflow

+2
Mar 04 '16 at 11:34
source share

Try adding the following meta tag at the top of the page to select the behavior of Internet Explorer 9:

 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9"> 

This is because conditional comments have been removed in the standards and modes of Internet Explorer 10 to improve HTML5 compatibility and compliance. This means that conditional comments are now treated as regular comments, as in other browsers. This change may affect pages written exclusively for Windows Internet Explorer or on pages that use browser bypass to change their behavior in Internet Explorer.

+1
Oct 31 '14 at 2:22
source share



All Articles