/  Technology   /  JavaScript onunload Event

JavaScript onunload Event

 

A JavaScript onunload event is triggered when a user attempts to load a page but is unsuccessful in doing so. It is possible that the onunload event will also occur if the browser has been closed while the page is loading.

The onunload event typically enters the onunload state when a user leaves a page while selecting, submitting, clicking, and leaving the browser window. In addition, this incident occurs when a user attempts to load a url or web browser and accesses data while it is loading.

Syntax

Using the javascript function, the onunload event is used for the html page. Below are the syntaxes for the HTML page and the javascript function.

HTML Syntax:

The attribute and value should be added to the HTML container or tag.

<element Onunload = "myData"> data </element> 

JavaScript Syntax:

The html attribute name should be used in javascript with a function.

object.onunload = function(){  
//javascript code.  
};  

Examples

Using the onunload JavaScript function, the user first calls a web page for its function, then tries closing the window to determine if the function has been loaded again using the script, and finally assigns an alert function using the script as indicated in the output.

 

Leave a comment