开发者

How do I prevent a line of JavaScript from running in IE (but let it run in other browsers)?

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 li开发者_如何学JAVAne 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜