« Katana can cut a bulletGlass Toilets »

Conditional Comments for IE and AJAX

Technical, Rant, Javascript, AJAX, 251 words   Bookmark and Share

One of the biggest grief in web development is fixing these minor quirks between Internet Explorer and Mozilla based browsers like Firefox. Microsoft then makes it more difficult with more quirks between IE5, IE6 and IE7. To give Microsoft some credit, they seem to have genuinely tried to make IE7 more standards compliant than its predecessors. Just yesterday, Conditional Comments placed in my code for adding addition JavaScript code to fix IE quirks gave me some grief. Let me explain further…

In IE, there is a feature called Conditional Comments which simply allows you to add comments in the following format:


<!–[if IE 7]>
<script>
alert("This is IE 7");
</script>
<![endif]–>

In short, these comments are ignored by most other standards compliant browsers but are recognized and processed by IE.
More info on Conditional Comments here http://www.quirksmode.org/css/condcom.html
(no this is not a condom site)

However, this becomes a problem on IE when content with JavaScript code is retrieved via AJAX. This is because most AJAX frameworks such as HTML_AJAX will scan through the content and extract code within the <script> tags ignoring the comment conditions. This has been verified on HTML AJAX 0.5.0 and hopefully some other frameworks do not have this problem or have since fixed it.

My solution to this problem involved adding conventional JavaScript based checks instead such as http://dean.edwards.name/weblog/2007/03/sniff/ for detecting IE and http://ajaxian.com/archives/detecting-ie7-in-javascript for detecting IE7

December 2024
Mon Tue Wed Thu Fri Sat Sun
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
 << <   > >>
Brinley Ang

Brinley Ang is a software engineer, sysadmin, coder, geek boy, jedi knight fragger, caffine addict, deaf meloncholic and rockstar wannabe. Listens to the sex pistols and a wide assortment of heavy metal.

Make payments with PayPal - it's fast, free and secure!
Search
home | portfolio | blog | links | contact
© 2024 - Brinley Ang
Valid xhtml