This is a very basic question. I have this script:
document.write writes to the document stream, calling document.write on a closed (loaded) document automatically calls document.open, which will clear the document.