[removed]() vs inserting DOM nodes: preserve form information?

后端 未结 4 1886
终归单人心
终归单人心 2020-12-19 08:05

Consider two web pages with the following in their body respectively:




        
4条回答
  •  我在风中等你
    2020-12-19 08:37

    document.write() won't blow away the page content as long as it is executed inline as the page is rendered. Online advertising makes extensive use of document.write() to dynamically write adverts into the page as it loads.

    If however, you executed the document.write() method at a later time in the page history (after the body is completely rendered) then as Chase says, it would blow away the existing body and display the argument to document.write().

    Other than that I agree that the preserving forms behaviour is really pretty browser specific, and not something you should rely on in many cases. It's a feature there to help the user rather than something for developers to be aware of or attempt to utilize.

提交回复
热议问题