It’s somewhat ironic that I happened to notice a paticular DOM bug today, of all days. Today, John Resig posted a blog entry called “The DOM is a Mess” in which he described–and posted a video link to–a talk he was asked to give at Yahoo recently.
As the title suggests, the talk was about how javascript is inextricably linked to the DOM, and how this entanglement has caused DOM-specific javascript to have lots of browser-specific bugs. In one of his slides, John says:
Nearly every DOM method is broken in some way, in some browser.
This is hard to believe, I know; but it’s true.
So, back to why we’re here. It just happens to be a coincidence that the day I watched John Resig’s video, I found a particularly nasty bug in IE. Now, I know I’m using the word bug loosely. I have yet to actually figure out what is causing the error. It is possible the error lies with flash. But as you will see in a moment, it is certainly very peculiar.
I noticed the bug when I was testing this very blog in IE 7. Here’s the wierd behavior:
Whenever I would refresh, leave, or close a tab in IE7 of a document which contained an <embed> element, I was receiving an “Object required” error. If that isn’t strange enough, the error seemed to always occur on “Line 53, character 3″ regardless of where the <embed> tag was in the page.
Here is my bug report page with bug isolated: http://polymath.mit.edu/projects/ieBugs/objectRequired/ieError.html.
Fortunately, I found a very simple fix. (Found here.)
<embed id="ieFixID"></embed>
<script type="text/javascript">
window.onbeforeunload = ieFix;
function ieFix() {
var ieFixElement = document.getElementById("ieFixID");
ieFixElement.parentNode.removeNode(ieFixElement);
}
</script>
The idea is to use the onbeforeunload event to remove the <embed> element before you leave the page. I’m still not 100% sure why this solution works, but hey, it does. So let’s not complain.
If anyone has seen this bug before and has any insight, it would be much appreciated.
Tags: bugs, DOM, ie, javascript
Posted in Web Development | 15 Comments »