I have been driving myself nuts trying to get comment conditionals to work and I'm not having any 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 is happening is frustratingly inconsistant. When I load the page with the above code in IE8 it get the message "IE IS LESS THAN VERSION 9" Great right? No because when I load the SAME PAGE in IE10 I get the message "Browser is not IE"
Why does it think that IE10 is not an IE browser?! I've been crawling page after page but there doesn't seem to be any thing wrong with my code from what I've found.
CSS Solution:
If you want to apply only CSS base on browser then you can try:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { /* Put your IE-only styles here. Works for IS 10 & IE 11*/ }
JavaScript Solution:
IE 10 does not support conditional statements.
Conditional statements in Internet Explorer 10.. It will treat conditional comments as regular HTML comments, and ignored entirely.
Use a feature detection library such as Modernizr instead of browser detection.
found a solution on impressivewebs in this comment:
Here is Demo to test
The solution is:
if (Function('/*@cc_on return document.documentMode===10@*/')()) { alert('IE 10'); } else { alert('Not IE 10'); }
It
I'm surprised that no one has added in a css-only solution. If you just want to use css, then use a statement like this:
@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 in the css and you are good to go.
Now, is it a hack? Likely. This depends on using the microsoft high-contrast tag, but since no other browser uses the ms tag then you should be good to go.
Finally, check out these pages for more info:
Blog Post
MS Site on the contrast tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With