6

I have developed a site that looks great in modern browsers like Chrome, Safari, Firefox and Opera, however, it looks terrible in older versions of Internet Explorer.

Is there some code that I can use that will prevent the page from loading if it detects an older version of IE?
Perhaps the code could load a different page?

Any ideas on how to best accomplish this? Thanks.

rodrigoap
  • 7,405
  • 35
  • 46
DanielAttard
  • 3,467
  • 9
  • 55
  • 104
  • 2
    This has been asked literally dozens of times before. See, as a small example, http://stackoverflow.com/questions/822508 http://stackoverflow.com/questions/1283704 http://stackoverflow.com/questions/280879 http://stackoverflow.com/questions/4743530 – BlueRaja - Danny Pflughoeft Jan 25 '12 at 22:20
  • possible duplicate of [How can I determine which version of IE a user is running in JavaScript?](http://stackoverflow.com/questions/280879/how-can-i-determine-which-version-of-ie-a-user-is-running-in-javascript) – Ken Redler Jan 26 '12 at 05:30

7 Answers7

3

Yeah for sure, you can use a client side re-direct, or a server-side redirect. OR You can just display different content based off the browser.

Javascript/jQuery:

if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
    // Do IE specific Tasks
    // window.location = "http://somewhat.com"
}else{
   //Do other tasks
}

PHP:

<?php
$browser = get_browser(null, true);
print_r($browser);
?>
Eric Hodonsky
  • 5,617
  • 4
  • 26
  • 36
  • 1
    I do not recommend sending the user away from your site ever. If you need to make a special splash page or some sort telling why you don't support IE do that. But try and keep the user engaged, and allow them an option to upgrade or switch browsers with instructions so they return to your site as soon as possible for the best experience. – Tim Jan 25 '12 at 22:27
  • @Tim yes, that was nice of you. Unless you were being facetious about the "http://somewhat.com" which is clearly a variable and not a string... it was meant to imply: "what ever your domain is". And I guess I could have also always just put that at the top of my answer too... – Eric Hodonsky Jan 25 '12 at 22:42
  • 1
    I posted the comment YOU posted on my answer about not redirecting users, because you first said that redirections are bad and then put redirection into your answer. – Tim Jan 25 '12 at 22:42
  • 1
    @Tim Ah, so you just misunderstood my answer then. I see. – Eric Hodonsky Jan 25 '12 at 22:43
1

For me it worked with

<script>
  if (window.navigator.userAgent.indexOf("Trident/") > 0) {
    alert("Internet Explorer is not supported.")
    window.location.replace("https://example.com/ie")
  }
</script>
M.S
  • 121
  • 1
  • 5
1

Use Internet Explorer conditional comments in your HTML

<!--[if lt IE 9]>
Insert your IE code, like possible redirection or alteration of your page
<![endif]-->
Perry
  • 2,250
  • 2
  • 19
  • 24
  • 1
    This is NOT a good way to publish your code. This is now considered a poor polyfill and should be avoided at all costs. – Eric Hodonsky Jan 25 '12 at 22:22
  • Depending on what is actually going wrong with his pages it could be all that is needed is some different styles for IE specific as is usually the case. IE conditionals might not be the best way to do it but it is the easiest and sure-proof way to do it. – Perry Jan 25 '12 at 22:51
  • actually the sure-proof way to do it, is to do a browser check on load, and apply the style to the body tag as a class. Then in your stylesheet cascade the need for anything in IE with this class preface. – Eric Hodonsky Jan 25 '12 at 22:55
  • 1
    @Relic Why on earth isn't this a good fix? If JS is disabled, no JS redirection or conditional logic or user agent detection will work. This conditional HTML comment works in the absence of the only language you can use to define behavior... In addition to that, the OP specified explicitly that he wants to prevent display of the page, and everybody still goes on about setting styles. He's past that point already. – Steven Lu Feb 04 '13 at 21:18
  • 1
    What I'm saying overall is this shouldn't be done. It's hacky... and now you're loading extra things for the browser to interpret, adds weight. If you think this is your solution, you're doing something else wrong all together. – Eric Hodonsky Feb 05 '13 at 23:26
  • Oh and serverside detection based off the headers sent with the request is PLENTY of information to conditionally respond with data specific to the browser. This also means less browser work. – Eric Hodonsky Feb 05 '13 at 23:27
1

You can use the USER_AGENT string in $_SERVER to look for user agents which contain strings unique to Internet Explorer. Then, you could just issue a header("Location: google.com") or redirect to a different page which warns about the dangers of IE.

Tim
  • 14,447
  • 6
  • 40
  • 63
  • I do not recommend sending the user away from your site ever. If you need to make a special splash page or some sort telling why you don't support IE do that. But try and keep the user engaged, and allow them an option to upgrade or switch browsers with instructions so they return to your site as soon as possible for the best experience. – Eric Hodonsky Jan 25 '12 at 22:25
0

Are you using jQuery in your website?

If so, you could utilize browser-validator-js (https://github.com/bml3i/browser-validator-js) to show friendly messages to user if they are using any version of IE. Just include the browser-validator-js and jQuery to the HTML HEAD, and add the below codes to the HTML BODY.

<script type="text/javascript">
    $(document).ready(function () {
        BrowserValidator.validateBrowser();
    }); 
</script>

This is an example: http://blog.bigcay.com/demo/browser_validator_demo.html

Leo Bi
  • 39
  • 4
0

You may want to consider adding Chrome Frame to your pages. http://code.google.com/chrome/chromeframe/

Scott
  • 16,711
  • 14
  • 75
  • 120
0

Check this out:

QuirksMode -- Browser detect

Paker
  • 2,522
  • 1
  • 16
  • 27