0

I have a way to find the version of IE... I need to find out if the current version is IE8:

if (navigator.appVersion.indexOf("MSIE 8.")!=-1)
{
    //do things
}

Is this an okay way to do this? I can't find much about doing this, but it seems pretty accurate to me.

Stefan Schouten
  • 249
  • 4
  • 14
  • 3
    What are you trying to accomplish in the end? [Why is browser sniffing not a recommended practice?](http://stackoverflow.com/questions/661213/why-is-browser-sniffing-not-a-recommended-practice) – Andreas Dec 10 '13 at 16:39
  • I am trying to add a piece of css to a page - but only if it's IE8. But my working environment will parse conditional comments as real comments - thus not including them in the front-end page. So I'm trying to find another way. – Stefan Schouten Dec 10 '13 at 16:42
  • Maybe this helps: [Target IE9 or IE8 but not both using CSS](http://stackoverflow.com/questions/5852681/target-ie9-or-ie8-but-not-both-using-css) – Andreas Dec 10 '13 at 16:52
  • 1
    Why is it bad that your working environment will parse conditional comments as real comments? A real comment should have no effect on your code anyway, and should still allow IE to parse and act on the conditional comments. – ajp15243 Dec 10 '13 at 16:54
  • I'm pretty sure conditional comments are the answer here. – gen_Eric Dec 10 '13 at 17:08
  • @ajp15243 exactly as I say, it doesn't include them in the page. So you see a page without comments. So every browser, even IE, won't receive any comments at all. – Stefan Schouten Dec 11 '13 at 09:15
  • There must be something else going on here to remove those comments, because conditional comments is probably the best way to detect different IE versions, and fit what you're trying to do, and there's no reason for them to simply disappear. It's difficult to say what is happening, however, without seeing your conditional comment markup (and perhaps any server-side code you might have that would be making the page where the conditional comments are). – ajp15243 Dec 11 '13 at 14:21
  • @ajp15243 The (customized) Zend Framework of our company removes the comments for - as far as I remember - bandwidth reasons. I can't get into the server-side code, so that's a no-go. – Stefan Schouten Dec 13 '13 at 11:03
  • I would like to add that I found too many problems with these conditional CSS-rules and that I've customized my HTML/CSS. Now it works in all browsers. Thanks for the help though! – Stefan Schouten Dec 13 '13 at 11:05

1 Answers1

1

You could try to use \0/ in the particular css property for IE8

e.g.

color: purple\0/;
Gotschi
  • 3,175
  • 2
  • 24
  • 22
  • 2
    I think it's either `\0/` for IE8 only, or `\9` for IE7 & 8 ([source](http://css-tricks.com/how-to-create-an-ie-only-stylesheet/)). – ajp15243 Dec 10 '13 at 16:58
  • Thanks! Works like a charm... Though it's still a hack. But I can't seem to do it another way. – Stefan Schouten Dec 11 '13 at 09:30
  • I would like to add that I found too many problems with these conditional CSS-rules and that I've customized my HTML/CSS. Now it works in all browsers. Thanks for the help though! – Stefan Schouten Dec 13 '13 at 11:06