ASP.NET: Warning on changed data closing windows

后端 未结 6 1511
深忆病人
深忆病人 2021-01-06 22:26

I\'d like to warn users when they try to close a browser window if they didn\'t save the changes they made in the web form.

I\'m us

6条回答
  •  無奈伤痛
    2021-01-06 22:44

    as others have mentioned, you'll want to look at the window.onunload/onbeforeunload events. The problem with this event is that it is called whenever the page is unloaded. Not only when the browser window is closed, but also when you click on a link within the same browser window to go to a different page on the same site. You still may be able to do what you want to do, but it helps if you can anticipate this behaviour.

提交回复
热议问题