Hello, alot of web advertising providers use the old document.write method, in my case AdTech. Is it possible to overwrite the document.write method to defer after the onload event?
Kind regards
Hello, alot of web advertising providers use the old document.write method, in my case AdTech. Is it possible to overwrite the document.write method to defer after the onload event?
Kind regards
Moving all your scripts to the bottom of the page (before >/body<) with advert scripts absolutely last and not using domReady at all (don't need it if your scripts are put in after all HTML elements) will do the same thing. In fact, it might be possible that defering document.write calls can even ruin the entire page depending on how aweful the advert code is.
you can output a
document.old_write=document.write;
window._bufferedText='';
document.write=function(text) {
window._bufferedText+=text;
}
//now let all the document.write go here
document.write('<h1>');
document.write('Hello World!');
document.write('</h1>');
//alert(window._bufferedText);
//end document.write methods
document.write=document.old_write;
document.write('<div id="deferred-write-placeholder"></div>');
window.onload=function() {
document.getElementById('deferred-write-placeholder').innerHTML=window._bufferedText;
delete window._bufferedText;
}
Notes:
document.write
code chunks.window.onload
with your javascript framework specific onload handler.