I\'ve got a script that inserts some content into an element using innerHTML
.
The content could for example be:
It's easier to use jquery $(parent).html(code)
instead of parent.innerHTML = code
:
var oldDocumentWrite = document.write;
var oldDocumentWriteln = document.writeln;
try {
document.write = function(code) {
$(parent).append(code);
}
document.writeln = function(code) {
document.write(code + "
");
}
$(parent).html(html);
} finally {
$(window).load(function() {
document.write = oldDocumentWrite
document.writeln = oldDocumentWriteln
})
}
This also works with scripts that use document.write
and scripts loaded via src
attribute. Unfortunately even this doesn't work with Google AdSense scripts.