Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Blocking ie7 and below

    Hi I want block ie7 and below from accessing a new website I have developed. How can I detect their browser and display a message prompting them to upgrade or use another browser if they come on the website in an old version of ie...

    Thanks

    Eddie

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,468
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    if (!document.getElementById){
     alert('update');
    }
    should do
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,485
    Thanks
    6
    Thanked 981 Times in 954 Posts
    But IE 7 (and 6 and 5) do support this method, so that’s not the way to check for old versions of IE. Here is a list of supported and not supported DOM methods. From a quick glimpse, it looks like the method matching most is querySelector or querySelectorAll.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Use IE conditional comments.

    Code:
    <!--[if lte IE 7]>
    Upgrade your browser.
    <![endif]-->

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thx for your responses, I found the Java code did not work? The <!--[if lte IE 7]> works fine although the site is still shown after the message... Is there anyway to just show a blank screen with this code?

    Cheers

  • #6
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,277
    Thanks
    28
    Thanked 272 Times in 266 Posts
    Quote Originally Posted by Eddie_E View Post
    Thx for your responses, I found the Java code did not work? The <!--[if lte IE 7]> works fine although the site is still shown after the message... Is there anyway to just show a blank screen with this code?
    Assuming that I remember how to use conditional comments correctly:

    Code:
    <!--[if gte IE 8]>-->
    <!doctype html>
    <html>[...regular webpage...]</html>
    <!--<![endif]-->
    
    <!--[if lte IE 7]>
    <!doctype html>
    <html>[...upgrade message...]</html>
    <![endif]-->
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    That's too big blocks of conditional comments.

    I would do it this way:

    PHP Code:
    <!doctype html>
    <!--[if 
    IE 9]>
    <
    html class="ie ie9">
    <![endif]-->
    <!--[if 
    IE 8]>
    <
    html class="ie ie8"><![endif]-->
    <!--[if 
    lte IE 7]>
    <
    html class="ie ie7">
    <![endif]-->
    <!--[if !
    IE]><!-->
    <
    html>
    <!--<![endif]-->
        <
    head>
        <
    style>
            
    #upgrade-message { display: none; }
            
    .ie7 #upgrade-message { display: block; }
            
    .ie7 #content { display: none; }    
        
    </style>
        </
    head>
        <
    body>
            <
    div id="upgrade-message">Please upgrade your browser.</div>
            <
    div id="content">
                
    //main content here
            
    </div>
        </
    body>
    </
    html

  • Users who have thanked glenngv for this post:

    Eddie_E (10-17-2013)

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    But personally, I don't like to be forced to use another browser. As a user, I prefer just a warning message that goes something like, "You are using a browser that we don't support. We encourage you to upgrade your browser. Some functionalities and layouts of this site might not work correctly, continue at your own risk.".

  • Users who have thanked glenngv for this post:

    Eddie_E (10-17-2013)

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,485
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Quote Originally Posted by Eddie_E View Post
    Is there anyway to just show a blank screen with this code?
    To be honest, if you were writing strictly semantic HTML and used progressive enhancement you wouldn’t need to show a blank screen to users of IE 7 (which is kinda discriminatory anyway). Instead, they would still be able to get the complete information they have potentially been looking for, just in a visually and functionally stripped down way, for those CSS properties and/or JS methods the browser doesn’t support.

    If you have to hide everything from people that use an old browser then you are doing something wrong, either technically or morally.

  • #10
    New Coder
    Join Date
    May 2008
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts
    It is a complex site full of lots of JQuery scripts that cannot be displayed on ie7. The client will not pay extra to make it compatible for this version and because of the complexity in the initial spec I did not add this compatibility to the cost as its like creating a new version. The client does not want to display it as it is on ie7 hence why its removed... and to be honest ie7 is dead anyway and explorer should do developers a favour and just make ie7 and below not available for any users... even ie8 is useless... what is the point of removing flash and making everything html5 if ie8 doesn't display either this either, but that's another topic...

    Thanks glenngv the code worked a treat

    Eddie

  • #11
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,485
    Thanks
    6
    Thanked 981 Times in 954 Posts
    But as I said, the approach is wrong. Even a site full of jQuery should not rely on jQuery/JavaScript for it to function (exceptions apply but I doubt your site is such an exception). Even in modern browsers people can (and do) disable JavaScript (at least partially if not completely). And may I guess that the only reason why people come to that site is to retreive information, not because of the fancy animations and whatever effects there are? Why would you withhold the information just because a browser doesn’t support one or another CSS property? That makes no sense whatsoever, much less if you are a serious business.

    And as I also said: If you were applying the principle of progressive enhancement right from the start you wouldn’t even need to “create a new version”. You would just use that version and enhance it with JS and all modern CSS, and it wouldn’t even be substantially more work (at least in the long run). People would get a basic version in non-supporting browsers (but at least they get the information they were coming for) and a fancy version if they decide to. But it’s all the same base, it just needs a little more consideration in advance by the developer.

    I’ve been preaching this all the time and I’m going to continue as long as people just throw random scripts together because they think they are fancy without thinking about usability and accessibility.

  • #12
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with VIPStephan on this. It is really not a good practice to block users from your page's content simply because their browser does not supports some JavaScript/jQuery you are using (or even CSS styles for that matter). In cases like that just don't provide the functionality for ie7 and below and offer a stripped down version of the site, but never block users from your page's content.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •