views:

45

answers:

3

I am looking for something similar to CSS's <!--[if IE]> decaration for JavaScript. I don't have time to find out why a line of code is not working in IE, and commenting it out doesn't break the page, so I am thinking "stuff IE" and looking for a way to comment the line out only for IE.

Any ideas?

+2  A: 

Conditional comments will work fine for this, too.

<!--[if IE]>
<script>alert("Hi, this is IE!");</script>
<![endif]-->
Pekka
A: 

navigator.appName will contain the browsers name, in your case you are looking for 'Microsoft Internet Explorer' so that would be your condition in this case:

if (navigator.appName != 'Microsoft Internet Explorer')

I would search for better browser detection than this since this is as simple and small as it gets.

DoXicK
thank you, this does the trick
ben
+1  A: 

You can use the (deprecated but entirely functional) $.browser.msie jQuery functionality.

(You could also copy the line of code over and we could see if we can see the IE issue.)

lonesomeday
http://stackoverflow.com/questions/3986564/why-doesnt-ie-let-me-create-img-elements-using-jquery
ben