document.write After Load
browser tricks 1997 partlyCalling document.write once the page has finished loading wipes the page and starts a new one.
In 2026: Still true, and still a real bug people hit. During parsing document.write inserts at the current point. After load it implicitly calls document.open, which clears everything. The demo below destroys its own frame three seconds in.
Where it came from: Netscape JavaScript Guide, 1997, which warns about it in a note most people did not read. MDN ↗
<h2>This heading exists right now.</h2>
<p>Watch it disappear in three seconds.</p>
<script language="JavaScript">
setTimeout(function () {
// After load, this implicitly calls document.open() first.
document.write("<h2>Everything above is gone.</h2>");
document.write("<p>document.write after load replaces the whole document.</p>");
document.close();
}, 3000);
</script>