Most Helpful
Most Helpful
There are 2 events for unloading that you should know.
Onunload and onbeforeunload
The onunload event fires when a page is unloading - it doesn't provide you any option to stop it from happening, it just informs you that it is happening.
The onbeforeunload event is much more useful (details msdn.microsoft.com%28VS.85%29.aspx) and it provides you notice that the user is trying to navigate away from the page, and gives you the opportunity to provide a message to the user with the option to cancel their navigation and remain on the page.
It is very commonly used on complex forms to ensure the user didn't accidentally click a link that would take them away and cause them to lose all their work.
Onunload and onbeforeunload
The onunload event fires when a page is unloading - it doesn't provide you any option to stop it from happening, it just informs you that it is happening.
The onbeforeunload event is much more useful (details msdn.microsoft.com%28VS.85%29.aspx) and it provides you notice that the user is trying to navigate away from the page, and gives you the opportunity to provide a message to the user with the option to cancel their navigation and remain on the page.
It is very commonly used on complex forms to ensure the user didn't accidentally click a link that would take them away and cause them to lose all their work.
The unload event specifically runs when the user exits a page. The event cannot be stopped or delayed. There are some web apps that use the unload event to save or store a user's work right before the exit a page.
You can follow www.comptechdoc.org for more information on JS Events.
You can follow www.comptechdoc.org for more information on JS Events.