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?
,
Conditional comments will work fine for this, too.
<!--if IE>
<script>alert("Hi, this is IE!");</script>
<!endif-->
,
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.)
,
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.