Document.write resets the body once

When I used document.write after loading the body (via the onclick event), it overwrites the whole object. I want this, which I am trying to achieve. However, when I do this again, it simply adds to the previous content. Why does he rewrite everything for the first time and only adds it the next time?

+3
source share
2 answers

If the document is not open for recording, the call document.writewill automatically call document.open.

At the first call, the document.writebrowser downloaded the document and, thus, closed it for recording. This calls document.open, which wipes the existing document and creates a new one for writing.

, , docment.write. document.close document.open, .

. https://developer.mozilla.org/en/document.write.

+11

document.write, /. - , , :

document.getElementById('elementID').innerHTML = 'your string';
+2

Source: https://habr.com/ru/post/1781698/


All Articles