Question

I never thought that I am stupid, but... I found hundreds of ways to create if statement in html. Some says that right way is:

<!--[if IE]>
   You're using IE!
<![endif]-->
<![if !IE]>
   You're using something else!
<![endif]>

Or this:

<![if !IE]>
//code
<![endif]>

Or look this fiddle: http://jsfiddle.net/APFZh/2/

All of this DON'T works on my pc. Why? All says that "you have to do this..." and such answers are suggested, so they have to contain working examples, but...

Why they don't work in my browsers? What is the correct way to write conditional statements? Is example from fiddle is working?

enter image description here

I tried to open fiddle in ie 11, not with FF and changed useragent. Epic.

Why it is so ? What I have to do? Help me please!

Was it helpful?

Solution

Conditional comments were disabled in IE10 so they will not work in IE11.

Source

In order to have conditional statements you can use Javascript to detect the browser. Since I see Mootools in your screenshot, here is a guide on how to do that.

Or, here is a JS library that is pretty good: WhichBrowser

That being said, browser sniffing is not recommended. Look into Feature Detection instead.

OTHER TIPS

You are not closing the comment tags correctly - it should look like this

<!--[if IE]>
   You're using IE!
<![endif]-->

<!--[if !IE]>
   You're using something else!
<![endif]-->

For extensive information on Conditional Statements see - http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top