0

I have included the following in the < head > content of my php page:

<script>
    if ($.browser.msie && parseInt($.browser.version) < 10)
    {
      console.log('You need v10 of IE or greater to use this app');
      alert("You are using an outdated browser and will be redirected");
      window.location.href = 'error.php';
    }
</script>

I basically want every visitor using Microsoft Internet Explorer 9 or below to go to the error.php page which states I want them to install version 10.

The problem that I am faciing is that this doesn't work unless I go to the developer part and instantiate the compatability features mimicking version 7, 8 and 9 when it then does work - merely going to my website with an old version it just loads up and not displaying the message / redirect...

Does anyone have any ideas or is it my code that is wrong? Thanks for looking.

Palendrone
  • 363
  • 1
  • 2
  • 14
  • Might have something to do with this: http://stackoverflow.com/a/3326655/1324019 – Mansfield May 16 '13 at 12:53
  • Be aware that `$.browser` is deprecated and not recommended for use (it was removed entirely from the most recent versions of jQuery). You should use feature detection, not browser detection to determine whether the user's browser is capable of displaying your page. – Spudley May 16 '13 at 12:55
  • 2
    *Go away. Give Microsoft money for a new version of Windows. Spend half a day upgrading your computer. **Then** and only then are you worthy to view my website.* — Well, I know what my reaction to that would be … – Quentin May 16 '13 at 12:59

3 Answers3

4

You should avoid testing for a specific browser but rather test for specific features that you need for your application to work. Then if they don't have those features show them the error.

This safeguards against browsers that you did not take into account.

You can test for features using Modernizr functions which will return false if the feature is not there.

You can use that site to build a version of Modernizr that only tests for the features you need.

--edit--

I told you what not to do but not why. In the comment below Chris makes a good point - browser sniffing just isn't reliable. There are pages and pages that you read about this, but current best practices says don't do it :)

tbwiii
  • 506
  • 3
  • 10
  • 1
    I agree here. But I do not know how PHP tests for browser version, type etc. But MSFT has decided to do the same thing the WebKit engine does and say it is Mozilla in order to trick outdated browser checks like this one because it is standards compliant, etc. So you may not even be checking for the right browser. http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx – Chris Love May 16 '13 at 13:21
  • "I do not know how PHP tests for browser version, type etc" — It does so poorly. – Quentin May 16 '13 at 13:31
1

Remove this line from your code....

console.log('You need v10 of IE or greater to use this app');

console.log isn't compatible with older IE versions...

bastos.sergio
  • 6,684
  • 4
  • 26
  • 36
0

You can use HTML conditionals. Place something like this in your body:

<!--[if lt IE 10]>
<script type="text/javascript">
    window.location = "http://yourbrowserisold.com";
</script>
<![endif]-->
belens
  • 962
  • 1
  • 8
  • 18