
How to Warn Users Before Their Browser Closes
Suppose a user enters some information on the page and tries to close or navigate from the window?without saving the data. You may want to warn the user about possible data loss. To do this, use the window DOM object’s onbeforeunload event, which is fired just before the unload event.