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;
  theHeadNode.insertBefore(newBase, theHeadNode.firstChild);


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