Alright so I want to Display a Browser Not Supported Message if the user is using IE 9 or less. Yes, I am limiting the users, I know. I want this done in JavaScript ONLY.

Anyway, I have found a way that checks for IE. If 'ie' = null the browser is not IE, If it isn't, then 'ie' = the version number.

I want to create a div that is white with a message in the center saying "Your Browser is Not Supported" with some icons showing supported browsers (Chrome, Safari, etc). If I can do this using a hard coded div element and css in an external file, with the script just changing the visibility then I would prefer it that way.

This will be edited to show code when I am have a computer available. Mobile doesn't show the button to add code.

Recommended Answers

All 12 Replies

You can simply add a div to your html page. Give the div an ID. In your css, set this element with the same ID to display:none. For example..

#div1 { display:none }

To display the div, set the div's display property to block in the function that you are using to check the browser version.

function IECheck()
    if (ieVersion < 9) 
        document.getElementById("div1").style.display = "block";

Here is the code:

window.onload = function()

function checkBrowser()
    var ie = /MSIE (\d+)/.exec(navigator.userAgent);
    ie = ie? ie[1] : null;

    if(ie && ie <= 9)
        //Display WhiteScreen and Message

I'll give it a shot, thanks for your help. Didn't see your post till after I posted the code.

The easiest way to test for IE9 or less is to check if HTML conditional comments are supported as only IE5 through IE9 support them and no one uses IE4 or earlier any more.

<!--[if IE]>Your old version of Internet Explorer is not supported on this site.<![endif]-->

No JavaScript is required to do this.

following up on felgall, here's what i use (practically the same); nothing else required, it remains hidden unless the browser is IE9 or less:

<!--[if lt IE 9]>
    <div id="yourID" class="yourClass">
        For the best viewing experience, ...

wazz, how does that get any other IE version less then 9? People still use IE 7 and 8. So I believe my version using a simple script works great. I just need to find someone that has IE 9 or less so I can test it.

Also for some reason I can't get my scripts to load. I think it's because they're in a sub folder, I'm calling it as
'<script src="Scripts/scriptName.js" type="text/javascript></script>'

In your browser's dev tools, use the console to see if errors are reported. If it fails to load, you will see 404 errors.

The path you specifies that the scripts are located in a subfolder relative to the page that is loading. If you have pages in different folders at diffrent levels, that path isn't going to work.

the first line: <!--[if lt IE 9]> means 'if less then IE 9'. that will take care of everything below 9. there are other options like <!--[if lte IE 9]> (if less than or equal to IE 9).

here's a source.

there's one catch i noticed after re-reading your post. 'my' code is great for hiding certain parts of a page. if you want the entire page to be blank when < IE9, you'll have to wrap everything in <!--[if gte IE 9]> (if greater than or equal to IE9, and add another block (div) with 'if less than IE 9'.

Alright, I just tried it, however I am using Chrome. Since I am not using IE at all, the stuff in the greater than isn't showing. Remedy?

IE conditional comments only work with IE 9 or earlier. They are ignored by other browsers because they are seen as comments.

sry, since i missed the fact that you wanted a blank page, things got muddled.
yep, wrapping everything else in that block doesn't work. you could go back to the js approach, but i did work out some styling that might do it for you.

    <title>Untitled Page</title>
    <style type="text/css">
        .ifIE {
            width:100%; }
    <!--[if lte IE 9]>
    <div class="ifIE">
        For the best viewing experience, ...

        all your good stuff
        more stuff

now there's just one conditional block that will show if users are on IE 9 or less. everything else remains on the page, but, i styled the IE-div so it takes up the entire page, covering everything else. if you make the background-color white it will look like a blank, white page (plus your IE-content, icons, etc.).

Thanks guys. Think I got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.