What bad things happen at the moment document.write() is invoked?
I’ve heard bits and pieces about document.write having an adverse impact on the DOM or on the use of Javascript libraries. I have an issue in front of me that I suspect is related, but have not been able to find a concise summary of what damage the method does.
Use of
document.write()will break a web page – destroying and overwriting the entire DOM – if it’s called after the document has finished being parsed. This is considered a poor use ofdocument.write()and is/was the reason for criticism of a lot of older scripts.Generally though, it’s acceptable and rather widely used at parse-time to add something dynamically to the page in a synchronous manner:
It’s mostly used by ad publishing services for adding the advertisements to a page, some Google APIs also use it.