There are main four load events in JavaScript.
onload – Run JavaScript code when the page has been loaded
onunload – Run JavaScript code when the browser closes the document
onerror – When an error occurs when loading an image
onresize – Run JavaScript code when the browser window is resized
We will learn all the load events one bye one with an example.
First learn onload event in JavaScript.
onload events occurs when html page loaded…
Below code show the example of onload events of JavaScript.
<html>
<head>
<script>
function Hi()
{
alert(“Your page is loaded”);
}
</script>
</head>
<body onload=”Hi()”>
</body>
</html>
The out put of onload events of JavaScript is :
Now, we learn onunload events of JavaScript.
onunload – Run JavaScript code when the browser closes the document
<html>
<head>
<script>
function Hi()
{
alert(“Thank you for visit Meera Academy”);
}
</script>
</head>
<body onunload=”Hi()”>
</body>
</html>
Now ,we learn onresize event of JavaScript.
onresize – Run JavaScript code when the browser window is resized
Here is the code for onresize events of JavaScript.
<html>
<head>
<script>
function Hi()
{
alert(“You have changed windows size”);
}
</script>
</head>
<body onresize=”Hi()”>
</body>
</html>
I hope this load events of JavaScript example will help you…..