16

does anyone have a script for checking for old browsers. It would have to follow this criteria:

  1. Allow firefox 3.6 or up

  2. Allow Google Chrome 15 and up

  3. Allow Safari 5 or up

  4. Block IE and opera

  5. Block all other browsers

Brian Webster
  • 27,545
  • 47
  • 143
  • 218
  • 6
    You should prefer feature detection over browser detection. See, e.g., [Modernirz](http://modernizr.com/). – Sirko Apr 21 '12 at 09:38
  • Seconding Sirko for feature detection. If you want to include names and version numbers, it should only be to offer suggestions if/when you detect the user's browser is lacking a feature you require. – searlea Apr 21 '12 at 09:41
  • 5
    block IE and Opera ? OMG – Luca Filosofi Apr 21 '12 at 09:44
  • 4
    How comes IE9 and Opera 11 is old , but Firefox 3.6 is "new" ? **What is the problem you are actually trying to solve ?** Instead of banning 75%+ of userbase .. – tereško Apr 21 '12 at 10:09
  • Just hopping by ... You can go through this answer http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – Runcorn Oct 07 '14 at 05:06

2 Answers2

36

You can use navigator object for this and in that you can use userAgent property like

 if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6){//Firefox
 //Allow
 }else if (navigator.userAgent.indexOf('Chrome') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Chrome') + 7).split(' ')[0]) >= 15){//Chrome
 //Allow
 }else if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Version') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Version') + 8).split(' ')[0]) >= 5){//Safari
 //Allow
 }else{
 // Block
 }
Ravindra Gullapalli
  • 8,591
  • 3
  • 41
  • 66
  • @JackRenshaw .. and it is completely useless , since browsers can be masked as any other and you can even turn off javascript. – tereško Apr 21 '12 at 11:11
1

I agree with with @Sirko. Preferably, you should use feature-detection instead. An alternative to to Modernizr would be jQuery's $.support() function. It's not exactly the same thing, but it may suit your needs.

If you insist on browser-detection, you can write your own script using jQuery's $.browser() function.

Ayman Safadi
  • 11,348
  • 1
  • 25
  • 41