Tuesday, February 06, 2007

Here's a javaScript fix for the BASE element IE6 bug: the BASE element becomes parent for all following tags if it is not closed with < / base > . As a result: selection problems and unexpected DOM tree (the parent for the BODY tag is the BASE element).

function fixIEBaseTagBug() {
if (is.ie) {
var bases = document.getElementsByTagName('BASE');
if (bases.length) {
 if(bases[0].innerHTML != '') {
  var theHeadNode = document.getElementsByTagName("head")[0];
  var newBase = document.createElement('BASE');
  newBase.href = bases[0].href;
  bases[0].removeNode();
  theHeadNode.insertBefore(newBase, theHeadNode.firstChild);
 }
}
}
};

Cheers

P.S. some details on the BASE tag here on MSDN:

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/base.asp