Thursday, August 16, 2007

7-es elotti IE-nel problemat okozhat a HEAD-hez uj elem hozzaadasa, ha van mar beolvasott BASE tag

A korabban itt es itt emlegetett dinamikus javascript betoltessel kapcsolatban Shaun Inman belefuott egy problemaba IE-nel (7-esnel regebbi):

Ran into a JavaScript problem with everybody’s favorite browser recently. Manipulating the head element from within (say by adding additional script or link elements before the page loads) was resulting in an enormously helpful “Operation Aborted” error message in versions of Internet Explorer prior to 7. Of course, like all things IE, this error’s appearance was inconsistent.

I was eventually able to track the problem down to the presence of a base tag. It didn’t matter if it was an open <base> or a self-closing <base />, if it came before the <script> that was manipulating the head, then IE stopped everything and issued the error. (At this point in script execution document.getElementsByTagName('head')[0] is a valid HTML element so testing for its availability before attempting to appendChild() doesn’t avoid the error. try/catch() is also of no assistance.)