If you have access to the specified .js file, the best solution would be to change the document.write () method and replace it with one that makes sense in order to distribute the contents contained inside.
The reasons for this are very well described above.
If you use document.write to write html tags to a page:
document.write("<script src=...></script>");
or
document.write("<img href=... />");
Consider using the same type of asynchronous format that you already used:
// Add/Remove/Sugar these components to taste script = document.createElement("script"); script.onload = function () { namespaced.func.init(); }; script.src = "http://..."; document.getElementsByTagName("script")[0].parentNode.appendChild(script);
If you want to add DOM elements for viewing and user interaction, you would also be better off:
a) Capturing a specific container (section / div) by id and adding your content:
document.getElementById("price").innerHTML = "<span>$39.95</span>";
b) Building content outside the DOM and entering it into the container:
var frag = document.createDocumentFragment(), span = document.createElement("span"); span.innerText = "39.95"; frag.appendChild(span); document.getElementById("price").appendChild(frag);
Again, sugar to your liking.
If you do not have access to this second .js file, I would suggest taking it with you.
source share