Force browser update if IE8 or older

18,392

Solution 1

You have two options:

  1. Parse the the User-Agent String

    // Returns the version of Internet Explorer or a -1
    // (indicating the use of another browser).
    function getInternetExplorerVersion() {
        var rv = -1; // Return value assumes failure.
    
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var ua = navigator.userAgent;
            var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    
            if (re.exec(ua) != null) {
                rv = parseFloat( RegExp.$1 );
            }
        }
    
        return rv;
    }
    
    function checkVersion() {
        var msg = "You're not using Internet Explorer.";
        var ver = getInternetExplorerVersion();
    
        if ( ver > -1 ) {
            if ( ver >= 9.0 ) {
                msg = "You're using a recent copy of Internet Explorer."
            }
            else {
                msg = "You should upgrade your copy of Internet Explorer.";
            }
        }
        alert(msg);
    }
    
  2. Using Conditional Comments:

    <!--[if gte IE 9]>
    <p>You're using a recent version of Internet Explorer.</p>
    <![endif]-->
    
    <!--[if lt IE 8]>
    <p>Hm. You should upgrade your copy of Internet Explorer.</p>
    <![endif]-->
    
    <![if !IE]>
    <p>You're not using Internet Explorer.</p>
    <![endif]>
    

Reference: Detecting Windows Internet Explorer More Effectively

Solution 2

You could use something like this

The ie6-upgrade-warning is a little script (7.9kb) that displays a warning message politely informing the user to upgrade the browser to a newer version (links to newest IE, Firefox, Opera, Safari, Chrome are provided).

The webpage is still visible behind a transparent background, but access to it is prevented. The idea is to force users to upgrade from IE6 and avoid the website from a bad reputation that website is not rendering correctly in IE6.

The script is completely translatable in any language, very easy to set-up (one line of code in webpage and one parametter configuration).

Although was created to be used with IE6 users, using the correct parameters you can use it for your scenario.

Solution 3

<script> var ISOLDIE = false; </script>
<!--[if lt IE 9]>
     <script> var ISOLDIE = true; </script>
<![endif]-->

Then later on, where ever you want to draw the line for supporting older versions of IE in your code:

<script>

     if(ISOLDIE) {
          alert("Your browser currently does not support this feature. Please upgrade.");
          window.location = 'http://google.com/chrome';
     }

</script>

It's typically not a good idea to completely remove IE8 support, which is why I think the above solution is a good compromise, because you can add it to components of your website/web application which simply cannot be made to support IE8, but then you could (possibly) still support IE8 in other areas of your website.

Solution 4

There is this dutch website forcing IE6 and lower users to upgrade their browser, a little adjustment to the "If IE" code you can block from whatever version you like.

http://wijstoppenook.nl/nl/

Scroll down to step 4 and click download or "voorbeeld" for a demo, the first one is a top banner, the second one completely blocks the page.

The only downside, its all in dutch so you'd have to make up your own message.

Solution 5

Conditional comments are no longer supported in IE 10. WTF! Link

Share:
18,392
ProDraz
Author by

ProDraz

Updated on June 26, 2022

Comments

  • ProDraz
    ProDraz almost 2 years

    I wonder if it's possible to show a warning or open a pop-up, which would say update your IE to latest version or use Firefox / Chrome / Safari instead, when browser is Internet Explorer IE8 or older...

    I guess I should use that code below inside the tags...

    <!--[if lt IE 9]>
    ...i should use code here...
    <![endif]-->
    

    Is it smart to deceted browser with jQuery and loading jQuery lib? Or is it better to just use regular javascript in order to avoid additional issues with very old browsers?

  • Paint_Ninja
    Paint_Ninja over 9 years
    Good, but chances are that if someone's on an old IE version, they are an enterprise that relies on IE-specific features or a PC novice who doesn't really know what a web browser is and just knows to click "the blue e". In cases like these, it may be better to include links for upgrading IE and other browsers, rather than just one specific competing web browser.
  • Jan Bludau
    Jan Bludau about 4 years
    IE10 and IE11 are dead. Now Edge with Chromium is uptodate :-)
  • Justin Liu
    Justin Liu almost 4 years
    <!--[if lte IE 6]><script src="js/ie6/warning.js"></script><script>window.onload=funct‌​ion(){e("js/ie6/")}<‌​/script><![endif]-->