Block Internet Explorer

Asked

Viewed 1,195 times

4

IE has a really bad performance on my website. Do Not Work Rounded Edges on Buttons, and some other defects. Basically, Internet Explorer is being Extinguished by Mozilla Firefox and By Fellow Chrome (Not Counting in Successor, the Microsoft Edge, Before called Spartan).

I would like a Code that detects the Browser, and If the user was using IE, Redirect to another page. On that page, I would suggest Download Mozilla or Chrome

Thank you.

  • 2

    Maybe you should use some framework like the Modernizr and treat these features instead of blocking access. - "Force me to switch browsers that never access your site again, or rather, find a competitor that supports what I use".

3 answers

6

Javascript

To detect IE in a version <= to 11 I think you can use:

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

Example: http://jsbin.com/dulisibuqa/1/

The ActiveXObject is a property found only in IE and the .documentMode indicates the IE version, and I believe it is consistent with small differences in the more recent versions em_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();
}

3

In order not to lose the habit, try to use Frameworks like Bootstrap that work thinking about the compatibility issue, which does not make you have much work, and eventually deal with these boring things, 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 on functions:

  • What I’d like is for him to redirect to another page.

  • So only one text will appear.

  • 1

    Instead of die place window.location.href = "http://site.com/bloqueado";.

  • 1

    @Rafaelalmeida this is javascript... and the answer is in PHP.

  • 1

    @Hugomarcelo instead of die place header('Location: /pasta/pagina-escolhida.html'); exit; :)

  • Note: this code can also block IE versions >11.

Show 1 more comment

1

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

The best alternative is to follow another path: work with the limitations of the browser and circumvent them whenever possible. And as pointed out in the comment on your question, you can use the Modernizr to detect whether the browser supports the Features you use on your website.

There’s also the tool Site scan that helps to detect possible problems beyond points to improve on your website. This can help make your site work properly on different browsers.

Here are some 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.