The only way to use document.write after the page has finished rendering is to temporarily replace the function with one of your own solutions that will insert content into the div. For instance.
function horriblefunction() { var old_dw = document.write; document.write = function(text) { document.getElementById( 'some_div' ).innerHTML = text; }
This will work as long as the external JS is already loaded and you just call the function. If you need to load JS (say by inserting a new <script> in the DOM), remember that this operation is asynchronous, and you will need to see how the DOM finds out when it is safe to restore the old version of document.write .
source share