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
3 Answers
Reset to default 10The 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]-->