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

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

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




        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 08:31

    I believe the document.write version actually blows away an existing content on the page. Ie, the body and script tags will no longer be there. That is why people usually use appendChild.

    Keeping the text or not is very browser specific. I wouldn't bet that Firefox would not change it's behavior on that in a future version, either. I would suggest implementing an alert dialog when the user trys to navigate away from the page and there is unsaved content in edit fields. Usually you would do this with an unload event.

提交回复
热议问题