I am a newbie, So I recorded it. This answer is shown in Baidu, so it is reprinted.
The following explains how to overwrite the entire document if document. write is called after the page is loaded.
In the prompt, "HTML output" indicates when the page is loaded.
Copy codeThe Code is as follows:
<Html>
<Head> <Body>
<Script type = "text/javascript"> document. write ("<p> Hello </p>"); </script>
</Body>
</Html>
After the page is loaded, you will see Hello on the page. View the source file is the above Code.
-------------------------
However, if the page has been loaded and document. write is used, the entire document will be overwritten.
Copy codeThe Code is as follows:
<Html>
<Head> <Body>
<Script type = "text/javascript">
// Call document. write when you click the mouse
Document. onclick = function (){
Document. write ("<span> Javascript </span> ");
};
</Script>
</Body>
</Html>
Because the mouse action is executed after the page is loaded, the whole page is overwritten by <span> Javascript </span>. Now, only <span> Javascript </span> is displayed when you view the source file.