Categories:
Partners
Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

onLoad Event handlers

The onload event handler is used to call the execution of JavaScript after a page, frame or image has completely loaded. It is added like this:

<body onload="inform()"> //Execution of code //will begin after the page has loaded.

<frameset onload="inform()"> //Execution of code //will begin after the current frame has loaded.

<img src="whatever.gif" onload="inform()"> //Execution of code will begin after the image //has loaded.

Lets see an example of an onload handler:

<html>
<head><title>Body onload example</title>
</head>
<body onload="alert('This page has finished loading!')">
Welcome to my page
</body>
</html>

Depending on the complexity or nature of your JavaScript, sometimes it is necessary to wait until the entire page has loaded before that script is run to prevent any potential problems or make sure the aspect of the page you're manipulating has been downloaded. This is where the onload event handler comes in handy.

Executing a JavaScript function after the page has loaded is necessary sometimes

Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.