onunload Event in JavaScript
onunload Event in JavaScript
The onunload event is used to trigger when once a page has unloaded. In other words, the browser window is closed. This event occurs when the user navigates away from the page. Refresh will also trigger this event. It is applied to the body element.
Syntax:-
Its syntax is:- < element onunload="my_script" > OR object.onunload= function(){my_script} OR object.addEventListener("unload", my_script)