IE9 and the old bgiframe bug

Does your awesome script don’t work on IE9? Is it producing this error SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5) on Google Chrome? It is most probably caused by the old jQuery bgiframe plugin which incorrectly identifies IE9 as IE6, thus wrecking havoc to the valid codebase.

Root cause

The root cause of the problem is the bgiframe plugin itself, specifically to its browser detection logic. As we all know, the jQuery bgiframe plugin is used as an IE6 hack so that floating containers will not see through select form elements. Here is how it checks for IE6:

if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
    // the code for IE6 here
}

As you can see, it only looks for the presents of the string 6.0 and it will assume that the browser is IE6. And here is the user agent for the common IE9 browsers:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8 )

Therefore it incorrectly identifies IE9 as IE6.

Solution

We should not be supporting IE6 this days so the easy fix is to remove completely the plugin. However, it for some reason you still wanted to support IE6 or simply don’t want to take risk breaking the existing codebase, here is the simple fix: use Query’s browser sniffer or use your own better IE6 detection script.

For jQuery’s browser detector, here we go:

if ( $.browser.msie && parseInt($.browser.version) === 6 ) {
    // IE6 code here
}

What a relief.

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *