0

I have a piece of functionality which needs to differ between IE8 and IE9 (IE9 uses a very nice library that is the main code path, but a slight minority of users of the app are still on IE8 which the library breaks under. So I need to gracefully degrade to less-nice library for them).

What is the best way to distinguish IE8 from IE9?

If possible, I'd like a version of the answer which treats IE9 with IE8 compatibility turned on as IE8; and one that treats it as IE9.

There's zero need to detect any other browsers or IE versions - this is for a locked down corporate environment so there's no risk of needing to detect beyond those 2.

DVK
  • 126,886
  • 32
  • 213
  • 327
  • Conditional comments. –  Jul 15 '13 at 16:50
  • 2
    [Browser detection](http://www.quirksmode.org/js/detect.html) – Robert Harvey Jul 15 '13 at 16:51
  • @CrazyTrain - you mean like this? http://stackoverflow.com/questions/1692129/conditional-comment-for-except-ie8 – DVK Jul 15 '13 at 16:51
  • Feature detection is generally the better way to go. – Andre Backlund Jul 15 '13 at 16:51
  • @RobertHarvey - WOW! Impressive! But that seems a tad bit of an overkill when I only need to distinguish between IE8 and IE9? – DVK Jul 15 '13 at 16:53
  • @DVK Theres a version detection method in robert's javascript, you could just rip out the version detection pieces if you already know it'll be IE – Stephan Jul 15 '13 at 16:56
  • @DVK: Yes. Don't use techniques that rely on the user-agent. That can be spoofed. Conditional comments can't. –  Jul 15 '13 at 17:00
  • @CrazyTrain - Good point in general, though I am not worried about spoofing. This is a bugfix for a broken-on-IE8 coporate internal use app, NOT fancy security code :) – DVK Jul 15 '13 at 17:48
  • @DVK: Alright, just saying in general that it's a more reliable method if all you need is IE detection. –  Jul 15 '13 at 17:52

1 Answers1

1

Conditional Comments. There are some other alternatives but conditional comments are simple and functional. MSFT provides this information http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

user1659653
  • 334
  • 2
  • 5
  • 15