Conditional comments
Friday, 19 November 2004
I’ve received a number of questions about the way I promote Firefox on this website. IE users see a large red bar on top of every page that will basically tell them to get Firefox. Most questions were about the way I show this red bar… Well thanks to Microsoft, it is actually very simple. Oh, the irony.
IE supports something that is called conditional comments. They are basically an extension to the regular comments that are defined by the (X)HTML standards. Sounds complicated, but it really isn’t. The guys at Redmond even wrote very helpful tutorial about it.
In case you are wondering how my website looks like in IE, and what I am talking about, take a look at this screenshot:
This is what the code on my website looks like:
<!--[if IE]> <div class='message'> <h1>It appears you are using the Internet Explorer web browser...</h1> <p> <a href='http://www.spreadfirefox.com/community/?q=affiliates&id=3571&t=54'> <img src='http://www.rakaz.nl/nucleus/skins/rakaz/get.gif' alt='Get Firefox!' /> </a> This site relies heavily on web standards and unfortunatly Internet Explorer does not yet fully support web standards. Therefore your browser may not display this website correctly. We recommend that you download and try out a standards compliant browser such as Mozilla Firefox. </p> </div> <![endif]-->
Everything between the <!--
and -->
will be hidden from the browser, because the HTML standard defines this as a non-visual comment. IE however, recognized the [if IE]
part after the <!--
and does display the content inside the comment. The advantage of this approach: it is completely compatible with the (X)HTML standards and it does not rely on things like server side or javascript browser detection.
Dude, your site looks like **** in IE.
just what i was looking for thanks, i knew there was a solution like this, i just didn’t know exactly what was used
That’s really nifty!
Can you please make one for perl? lol
Oh, Nevermind. lol, I got it.
Fantastic!!
You should include the css style in the copy/paste code. I know it’s not standard, but it would be easier for other to include in their site.
Pour les francophones je viens de faire une version en fran
Nice one! Now I can finally tell all those IE jockeys to get a real browser. :)
I’m gonna use this in my site right now. Very clean coding using no server or client side scripting or the like.
Hi Niels!
Sorry for the offtopic.. but what is this theme you’re using in the screenshot?
aa
Nice! I’m sooooo gonna use this!
My site also displays a similar message (proudly) in IE. I’m just a little more blatant about it though, but I’ll change it to a more "proper" message soon.
Anyway, you can also do this using CSS if you like. Assuming you’ve got an ‘id’ attribute with the value ‘outdated’ in it on the element giving the warning, just insert the following line into your CSS:
body>#outdated { display: none; speak: none }
This will make the message disappear in better browsers, while leaving it displayed in IE. For a working example of this, just check my site.
I am inspired by your script and created Firebar. You can see it at http://hpstudios.homeip.net…
Geil!
First of all, this website looks REALLY good. And it’s really cute that this website requires Firefox, but dammit man, not even Firefox can scroll through this site at a sane speed… Scrolling is lagging A LOT.
Therefore, I don’t think I like this ‘standards-compliant’ website. No sir, it sucks.
Richard Personally I have no problems with lagging scrolling. And I am
using ‘only’ a Celeron 800 MHz here.
the site shows fine in Internet Explorer 5.2 for Macintosh, which is the "latest" version, but it does not support the if "IE" thing.
Rakaz, I just tried it on Firefox/win32 and scrolling appears a lot smoother (cetainly maximized at 1400×1200). Apparently this is a Firefox/GTK2 issue. Would you mind if I used this website as a reference for a bugreport I wish to submit to bugzilla?
Richard S: No problem to use this as a bugzilla example, however I do
think the people who might be going to work on this rather have a simplified
test case.
Hi. Just thought I would mention that I do not have any problems with scrolling this site using Firefox. It might just be done to CPU speeds… I’m currently running a 1G PC with Windows XP.
Yeah – funny thing. On most sites with fixed-width backgrounds and semi-transparent PNGs, scrolling [for me at least] using firefox is horrid. Even on a 2ghz AMD with 512mb ram with very little load.
However, that’s not the case here. Good job.
BTW: Almost certainly will be using your great little hack here, although I don’t believe it works for versions of IE for Mac (which is all right with me, because thanks to the wonders of CSS importing and such they don’t get a stylesheet anyway!).
This is a fantastic idea, and I hate to comment just to nitpick, but, uh, it’s
spelled ‘unfortunately’. You’ve got ‘unfortunatly’ in your screenshot, so I
just thought I’d give you the heads up. This just looks so good, it’s a shame
to be distracted by a typo. Again, fantastic idea, and after clicking around on
some commenters’ linked versions, I may try something similar myself. Thanks for
the inspiration.
You did inspire me to do the same on my site ( http://www.errorik.com/ ). I choose a CSS method, and my argument is that if IE was CSS compliant their users wouldn’t be subject to seeing the Firefox propaganda.
I found this interesting. A person is doing his “Switch to Firefox” campaign directly at IE users. Basically, he is making use of an IE feature that allows you to put conditional statements in HTML code. It is rather ironic…
Awesome idea! I am using it on my site now. http://gatewayy.net :) I just need need to figure out some weirdness with an alignment issue but thats not a big deal. :)
Hi, it’s a great idea and I’ve used it as the rel="nofollow">basis for a Get Firefox plug which doesn’t mess the layout of
the page up as much.
It’s not quite as visible as yours though! :)
nice!!! gonna apply it right away on my sites
btw, what is that visual style you all firefox devs use and that you use on this screenshot? please answer. thx.
Thanks for the tip!
Note: you can use this trick to spoof the ‘Info Bar’.
Hi,
I just thought it’d be appropriate to notify that I have adopted a slightly
modified version of your bar to my modest website
and at the same time thank you for bringing this technique into public
attention.
So… thanks. :)
Je viens de trouver un moyen plus radical de faire savoir aux visiteurs qu’Internet Explorer ne saura pas afficher le site.
Pour ceux d’entre vous qui veulent continuer
I used the same technic on my blog, it works very well.
Thanks a lot !
Et Firefox, c’est bien.
Voici donc une petite bidouille pour le faire comprendre aux utilisateurs effrontés d’Internet Explorer (viendez ici avec IE, pour voir).
Idée pompée sans vergogne
Very nice! My curiosity finally answered. Thanks!
I Will use it too, thank you !
A really good idea !
Great ! Way to go – Hope IE 7 would take this in to consideration !
How do you get the "red" box, it only appears the letters in my website….
Wait nevermind!!
Yea Richard, I don’t think it’s the web site, cuz I’m on a 400MHz K6 II, and the scrolling is fine, Then again I am running linux….
Your website looks so bad in IE! That’s awesome! I thought I was the only one who didn’t care if my site looked good in IE.
Thanks, I was after the syntax, other sites’ code caused Firefox to render “if IE 6″ code, this works brilliantly, thanks again.