Block Internet Explorer

4

IE has a very poor performance on my site. Do not Run Borders Rounded buttons, and some other defects. Basically, Internet Explorer is being Extinct by Mozilla Firefox and Chrome Companion (Not counting Successor, Microsoft Edge, formerly called Spartan).

I would like a code that detected the browser, and if the user was using IE, redirect to another page. On this page, I would suggest Downloading Mozilla or Chrome

Thank you.

    
asked by anonymous 04.05.2015 / 22:55

3 answers

6

JavaScript

To detect IE in a version of 11 I think you can use:

if ("ActiveXObject" in window && document.documentMode <= 11){
    alert('é IE <= 11');
    // ou: window.location.href = "http://novo.url"
}

Example: link

The ActiveXObject is a property only found in IE and .documentMode indicates the IE version, and I believe that it is consistent with small differences in the lower versions in_strict mode_, but certainly <=11 .

PHP

preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if(count($matches)<2){
  preg_match('/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
}

if (count($matches) > 1 && $matches[1] <= 11){
    header('Location: http://novo.url'); die();
}
    
04.05.2015 / 23:27
3

In order not to lose the custom, try to use frameworks like Bootstrap that work on the issue of compatibility, which does not make you have too much work, and eventually deal with those annoying things, the people will already do it for you. But in any case, below is the code.

if(preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']){
   die('Internet explorer bloqueado.');
}

For more information about functions :

04.05.2015 / 23:01
1

The idea of simply trying to block Internet Explorer or redirect the user to another page may be very aggressive for users who still use this browser.

The best alternative is to follow another path: work with browser limitations and bypass them whenever possible. And as pointed out in the comment to your question, you can use Modernizr to see if your browser supports the features you use on your site .

You also have the Site scan tool that helps you detect potential issues as well as points to improve on your site. This can help make your site work correctly in different browsers.

Here are also a few articles that describe more about how to make a website work better in IE and also how to make a website simply work in different browsers .

    
27.08.2015 / 21:57