Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

What's the best way to show a text message for only IE 6 and IE 7 ?

Should I add a html tag to my webpages and normally hide it with css for all browsers except the above mentioned ?

And when I use IE6 IE7, should I hide the website with css and show only that html tag ?

thanks

share|improve this question
    
Is your goal to keep IE6 & 7 users out of your website? –  John Conde Nov 1 '10 at 17:38
    
@John Conde yeah –  Patrick Nov 1 '10 at 17:50
    
Find an IE 6 & 7 virus and put it on your page. If they get infected, they have IE, make the virus hijack the browser and show a text message each time they load your site... Just kidding! ;) –  Itai Apr 8 '11 at 4:28

6 Answers 6

up vote 0 down vote accepted

It's tough to limit access to a website by browser because there is no 100% foolproof way to do it.

Your first problem is user-agent spoofing. Browsers can identify themselves with any user-agent they want to. Browsers with extensions all seem to have one that makes doing this trivial. If someone with IE6 or IE7 changed their user-agent to be that of IE8 or Firefox they'll get into a website.

You can use JavaScript to overcome that issue by using feature detection. Basically you use JavaScript to do a simple test: you check to see if a piece of functionality that doesn't exist in IE6 or IE7 exists. If it doesn't, you know it's them. The problem with this is if they turn off JavaScript they easily bypass this.

A multi-tiered approach would be to browser sniff on the server side using their user-agent, ideally in Apache or IIS, and redirect those users to a page telling them you don't support their browser. BTW, that's more polite then simply hiding the website. I'd augment that with the JavaScript feature detection method. Between the two of them you'll catch all but the most technically savy users and the odds are they aren't using IE6 or IE7 anyway.

share|improve this answer
    
@John Conde My questions actually was not about how to detect the browser, but how to show different content once the browser has been detected –  Patrick Nov 1 '10 at 17:52
1  
That is as easy as a redirect depending on how you choose to browser sniff. If you choose Apache then redirect to a special page in a .htaccess file. If you choose JavaScript use window.location. Just trying to hide the website with CSS still makes everything available to the user. They just can't see it without a little bit of effort. These ways you take them away from the content completely. –  John Conde Nov 1 '10 at 17:55
    
@John Conde oh yeah, you right –  Patrick Nov 1 '10 at 18:53
5  
there is a 100% foolproof way to do it, specifically for IE browsers. and that is conditional comments. saying there is no way, and then elaborating on ways it wont work with user-agents is not a good answer to this particular question, since it can be done without user-agent detection. –  Evgeny Nov 1 '10 at 20:13
2  
I can't believe this was choosen as the correct answer. –  Marco Demaio Nov 22 '10 at 20:21

Conditional CSS commenting or use the JQUERY browser detection:

Link to CSS conditional Comments

Link to Jquery browser detection

Using these you can set styles like hide the divs of normal content and display the divs of alternate content. Or us JS to alter the content and how it's displayed.

If you're looking to just remove everything for IE6 users and show them a message telling them to update you can set the CSS to hide everything inside the body, and throw an alert onload with the jquery detection. It's harsh, but should work the majority of the time so long as they aren't trying to be sneaky or bypass this. In which case they probably aren't the people you are targeting.

share|improve this answer
    
+1 the conditional comments will work best in most cases, since only IE browsers "understand" them. –  Evgeny Nov 1 '10 at 19:20
1  
Using jQuery browser detection to show a message on IE 6/7 it's like attempting to enter in your house through the window instead of using the door. –  Marco Demaio Nov 2 '10 at 13:54
    
Marco that comment is brilliant! Sadly it is a choice we have in our toolkit, but I will always imagine it as climbing into a window in my house now. Love it! –  XOPJ Nov 3 '10 at 13:19

Use Conditional Comments that only IE browsers support.

share|improve this answer

Add these type of HTML conditional comment in your page HTML source

<!--[if IE 6]>
<h1>Hello, u r using IE6, your message here</h1>
<![endif]-->

<!--[if IE 7]>
<h1>Hello, u r using IE7, your message here</h1>
<![endif]-->

<!--[if lt IE 8]>
<h1>Hello you are using a version of IE less than IE8, your message here</h1>
<![endif]-->

All above will be skipped like normal HTML comment by ALL browsers except IE that will parse these and beahve accordingly.

share|improve this answer

So - what's the reason to want to "hide the website" from ie6/7? if it's user agent specific messaging, I'd vote for conditional comments.

share|improve this answer

would the reason you would be showing different content is the reason you are using HTML5, which is non-compatible with IE7 & below?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.