ProDraz
ProDraz

Reputation: 1281

Force browser update if IE8 or older

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?

Upvotes: 6

Views: 18616

Answers (8)

Spinstaz
Spinstaz

Reputation: 331

This is what I have, which was in a bootstrap download:

<!--[if lt IE 8]>
  <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

So basically you can have lt or even lte less than or equal.

Upvotes: 0

epicrato
epicrato

Reputation: 8418

There are many ways, but this is by far the most elegant: http://outdatedbrowser.com/en/how

Upvotes: 0

antonjs
antonjs

Reputation: 14318

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

Upvotes: 6

Ankit Suthar
Ankit Suthar

Reputation: 181

On your site add your code to index.html or index.php

Its working also joomla and wordpress.

<!--[if IE 5]>
<script language="Javascript">
<!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 5.0]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 5.5]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 6]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->

<!--[if IE 7]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->

<!--[if IE 8]>
!--
alert ("It looks like you aren't using Internet Explorer 8. To see our site correctly, please update.")
//-->
</script>
<![endif]-->

Upvotes: 0

Jan Bludau
Jan Bludau

Reputation: 319

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

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

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.

Upvotes: 6

Leah Zorychta
Leah Zorychta

Reputation: 13419

<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.

Upvotes: 5

Erik Terwan
Erik Terwan

Reputation: 2780

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.

Upvotes: 2

Related Questions