Scold Internet Explorer users with conditional comments

Friday, January 4, 2008

It’s a sad, sad fact that the various versions of Internet Explorer still command a 57% marketshare in the browser world. Yes, supporting that craptastic pile of kludged-together code, with its hundreds of security holes and complete disregard for web standards, is a complete nightmare that has added hours upon hours to the development of this very page. Debugging pages in IE is almost enough to make me question why I want to do web development for a living. But there’s a way to whittle away at IE’s marketshare and (as I’ll mention later), make a bit of money in the process.

Making use of conditional comments

Conditional comments keep web developers sane. They’re only interpreted by IE and allow developers to section off IE-only code, allowing them to keep a page standards-compliant while still intentionally breaking their code so Internet Explorer’s completely b0rked engine will render it correctly. You can even choose which version or versions of IE to target!Conditional comments look a lot like standard HTML comments, with a bit of simple code added. For example, say you want to use a JavaScript hack to fix IE6’s handling of transparent PNG files. Clearly you should only burden the IE6 user with having to download this extra code, so use a conditional comment like this:

<!--[if IE 6]>
    <script defer type="text/javascript" src="js/png_fix.js"></script>
<![endif]-->

That’s it: IE6 will parse the comment and will go on to download png_fix.js. Using defer when referencing the script will cause the browser to wait until the page is done rendering before executing it, avoiding some funky-looking effects when applying this particular hack.

Caveats

There’s only one catch to conditional comments: if you’re running multiple versions of IE on the same machine, the comment wil be evaluated as the highest version you have installed, no matter which one you’re testing from. To get around this, you can use a Windows XP virtual machine with IE6 installed, which is graciously provided by Microsoft themselves. After subjecting the world to their sub-par browser, it’s the least they can do.

Making money with conditional comments

Yes, it’s possible to make money off something as nerdy as this. Google AdSense publishers have long enjoyed a hybrid CPA system called “Referrals,” which is like Google’s answer to Commission Junction. One of the offers in the AdSense CPA program pays $1 for getting people to switch to Firefox. Using a conditional comment at the top of your page to display a banner for this offer only to IE users gives you 100% targeted traffic, many of whom have likely heard of the benefits of Firefox before and were waiting for the “right moment” to switch. It won’t make you rich, but it’s a nice little tip for doing your part to chip away at the market dominance of a bottom-tier browser.

tags:                        

6 comments on Scold Internet Explorer users with conditional comments:

  1. You Can’t Get Rich if Your Browser is Broken | Can’t Get Rich Says:

    […] the history of software. Between eating up all half of your RAM, crashing for no apparent reason, ignoring web standards, and being more susceptible to spyware and viruses than any other browser on the market, it’s […]

  2. Some guy in Japan Says:

    Thanks for this post.

    I just reinstalled Windows and thus currently have IE6 installed. On a whim I loaded up Lucky Isle in it and gasped when I realized that my main logo relies on PNG transparency to show up correctly, . I completely forgot that IE6 doesn’t support them.

    Anyway, you happened to post this at the perfect time. Thanks for the help.

  3. The Evolution of a Landing Page | Can’t Get Rich Says:

    […] Nearly every theme that looks great in Firefox looks bad in IE7. After you’re done building the site, take a look at it in IE7 to make sure that everything is where it should be. If something is off, fix it by making a copy of the style sheet, renaming it, and messing around with the code until it looks right. You can then tell browsers which style sheet to use by adding some conditional comments. […]

  4. ReviewU: Gaming Chronicle | Can’t Get Rich Says:

    […] already using Firefox, so I shouldn’t be seeing that text. Familiarize yourself with conditional comments and make it so that only IE users see that […]

  5. Jason Says:

    Thanks for the post. I have been using a php file to determine the type of browser being used and deliver the content by changing the headers like I did for this McDonough Home Builder to deliver a separate style sheet for IE 6, 7 and the rest. It actually is a really great script, but I think I will give your way a try, it gets old having to update three style sheets when you want to make a change.

  6. iyi oyunlar Says:

    thanx man

Leave a comment and get your 2 cents in.

All fields are optional except for the comment body. All links are not 'nofollow,' so you will receive full SEO benefits as a reward for taking the time to comment. Valid HTML tags are <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . There is no comment policy. Enjoy!