最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - sniffing IE8 only - Stack Overflow

programmeradmin4浏览0评论

What's the shortest javascript code to sniff if the browser is IE8.

I want to do something special just for IE8

I don't want to wire up a library that gives me back all the browsers and the versions. I just want to write one or two lines to work out if it's IE8.

thanks zo

What's the shortest javascript code to sniff if the browser is IE8.

I want to do something special just for IE8

I don't want to wire up a library that gives me back all the browsers and the versions. I just want to write one or two lines to work out if it's IE8.

thanks zo

Share Improve this question edited Nov 29, 2011 at 12:11 Rene Pot 24.8k7 gold badges70 silver badges92 bronze badges asked Nov 29, 2011 at 12:08 Zo72Zo72 15.3k18 gold badges74 silver badges105 bronze badges 1
  • 3 Google- how to detect ie8 in javascript. – Matt Commented Nov 29, 2011 at 12:11
Add a ment  | 

3 Answers 3

Reset to default 10

The best way I found is to use conditional styles, or conditional piling:

var isIE8 = false;
<!--[if IE 8]>
        <script type='text/javascript'>
            isIE8 = true;
        </script>
<![endif]-->

Then in your code, you can simply check this value:

<script type='text/javascript'>
   if (isIE8) {
       alert('Your browser is IE8');
   }
</script>

You can do this in HTML, by using this:

<!--[if IE 8]>
<script type="text/javascript" src="IE8.js">
<![endif]-->

Also take a look at this tutorial: http://msdn.microsoft./en-us/library/ms537509%28v=vs.85%29.aspx

In your HTML, you can include markup for certain IE browsers using conditional ments:

<!--[if IE 8]>
<script type="text/javascript" src="ie8_hacks.js">
<![endif]-->
发布评论

评论列表(0)

  1. 暂无评论