-5

I want to detect the browser version when I load my page. i.e

If a user is using Internet Explorer 8 or Lower version an alert should appear.

How can I manage this using Javascript or Jquery ?

Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92
  • Why? If it's to say "your browser is not supported", you should detect *features*, not browsers. – Niet the Dark Absol Apr 04 '14 at 14:31
  • please google javascript detect browser, and you will find a lot of information. – Luis Tellez Apr 04 '14 at 14:32
  • 1
    I just want him to suggest to use latest browser – Hassan Sardar Apr 04 '14 at 14:32
  • 1
    [Classic example of XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You're not actually interested in detecting with JavaScript, you're interested in displaying a message to IE8 and below. Ask about your problem, not your solution. – zzzzBov Apr 04 '14 at 14:32

1 Answers1

1

To display a message to site visitors using IE8 and below, you should use a conditional comment:

<!--[if lte IE 8]>
Almost any HTML can go here, just not comments
<script>
alert("You're using an outdated browser!");
</script>
<h1>You're using an outdated browser!</h1>
<![endif]-->
zzzzBov
  • 174,988
  • 54
  • 320
  • 367
  • 1
    And same thing goes for i.e 10 or lower? – Hassan Sardar Apr 04 '14 at 14:39
  • 2
    @Necromancer, IE10+ no longer supports conditional comments. Generally you should avoid browser detection in favor of feature detection. There are certainly some exceptions, such as a site that displays browser information to visitors. – zzzzBov Apr 04 '14 at 14:42
  • What specifically do you have against IE9 or 10? it doesn't take much work (if any at all) to make code that works in modern browsers work correctly in IE9/10, other than a few leading edge features that aren't yet available (which you should feature test for, not browser test) – Kevin B Apr 04 '14 at 14:47
  • 1
    How can I show alert when the browser is IE 10 or less ? – Hassan Sardar Apr 04 '14 at 14:50