Thursday, August 03, 2006

A generic js function to append text in HTML

Here is a simple js function to append whatever you feel like after your document(html) is loaded in the user browser.

/*
*Append HTML to document.
*WORKS IN ALL BROWSERS
*/

function appendDocument(html)
{
if (document.all)
document.body.insertAdjacentHTML('beforeEnd', html);
else if (document.createRange) {
var range = document.createRange();
range.setStartAfter(document.body.lastChild);
var docFrag = range.createContextualFragment(html);
document.body.appendChild(docFrag);
}
else if (document.layers) {
var l = new Layer(window.innerWidth);
l.document.open();
l.document.write(html);
l.document.close();
l.top = document.height;
document.height += l.document.height;
l.visibility = 'show';
}
}

0 Comments:

Post a Comment

<< Home