Having conditional comments and CSS references inside them is good, having conditional comments give the body or html element a class is better, but in my opinion having all this in a JavaScrip file is better.
First thing is to take this code:
var IE = (function() { var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0] ); return v > 4 ? v : undef; }()); |
Now we have a reliable variable called IE which contains either undefined or the IE version. Now we can do real fun stuff with this:
/*IE support*/ if (IE==6) { $.getScript('lib/DD_belatedPNG_0.0.8a-min.js', function() { DD_belatedPNG.fix('img, .textInput, .apng,.picture-box-frame'); }); } if (IE) { $('html').addClass('ie'); $('html').addClass('ie'+IE); } |
We can load IE specific hacks from the script tag without bloating the HTML header and we can also add CSS classes to top level elements without filling our HTML header with conditional comments. This is a really clean and flexible approach that doesn’t force you to make your header look like trash.
NoScript
NoScript people will simply tell you that: “If the user has JavaScript disabled this will not work”
According to Yahoo approx. 2% of the US visitors have JavaScript disabled and far less in other parts of the world. But let’s take the 2% for users who for some reason don’t have JavaScript enabled, and discard everyone but the IE users and we get a number that’s far less then 2%. This is highly dependent on the product but if I have to break the experience for less then 2% of my users for the benefit of the remaining 98%, I think I will go with it.
A lot of IE hacks(like PNG hacks) will not work without JavaScript anyway so the user will still have a broken rendering even if I put the conditional CSS in the HTML.
If you are using jQuery you can use just if($.browser.msie && $.browser.version == 6) or even $.support
I looked into the source code of jQuery and I think those are determined by UA string parsing, which is not reliable.
This seems like a far more convoluted method of going about the problem. Though from the looks of your blog’s markup, you also don’t know how to use the IE conditional statements to load up an external stylesheet instead of forcing all users to download all of the IE conditional style rules you have in there.
Conditional JavaScript: http://migre.me/1F2Fi
> This seems like a far more convoluted method of going about the problem.
Depends how advanced the application you are making.
> Though from the looks of your blog’s markup, you also don’t know how to use the IE conditional statements to load up an external stylesheet
> Theme Design by devolux.nh2.me
This is a free WordPress Theme that I didn’t write.
I personally hate XHTML. I new theme is underway though to replace this one.
I could show you sites that I made recently.
> forcing all users to download all of the IE conditional style rules you have in there.
It depends on how much IE hacks it requires to get the job done. I tend to minimize the number of hacks required by simply working around them.
Conditional JavaScript – http://su.pr/2ijWcw
Helpful blog, bookmarked the website with hopes to read more!
Conditional JavaScript: http://bit.ly/bdQeXz via @addthis