JavaScript Load Events

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 :

learn JavaScript onload events

learn JavaScript onload events

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>

 

learn JavaScript onunload events

learn JavaScript onunload events

 

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>

learn JavaScript onresize events

learn JavaScript onresize events

I hope this load events of JavaScript example will help you…..

 

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 9 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">