Click to See Complete Forum and Search --> : "emulating" DOM -- contributions please!


Dudsmack
12-03-2003, 05:37 PM
Been working on emulating DOM on 4th generation browsers and this is what I have so far. I know it's small and simple but so far it's worked quite well in all my test. Only two problems I found are that if you use innerHTML before the page loads in Opera 5 and under it crashes the browsers, and you can't use innerHTML to recieve a string of the current contents of the object. Here's the code, disect, play with it, improve, find bugs....I'm sure this is something all of us could use.


(document.getElementById) ? null : document.getElementById = new function(objectName)
{
//the browser isn't W3C compatible so let's emulate it

if (document.all) //IE4 and WebTV browsers
{
return document.all[objectName];
}
if (document.layers) //Netscape 4 and browsers with the 'rhino' engine
{
tempObject = null;
tempObject.style = document.layers[objectName];
tempObject.style.backgroundColor = document.layers[objectName].bgColor;
tempObject.style.backgroundImage = document.layers[objectName].background;
tempObject.innerHTML = new function(newContents)
{
eval(objectName + '.document').open();
eval(objectName + '.document').write(newContents);
eval(objectName + '.document').close();
}
return tempObject;
}
}

Thanks in advance!