X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

onload Event

Event Object Reference Event Object

Example

Execute a JavaScript when a page is finished loading:

<body onload="myFunction()">

Try it yourself »
(more examples at the bottom of this page)


Definition and Usage

The onload event occurs when an object has been loaded.

onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).

Syntax

In HTML:

<body onload="SomeJavaScriptCode">

In JavaScript:

window.onload=function(){SomeJavaScriptCode};

Parameter Description
SomeJavaScriptCode Required. Specifies a JavaScript to be executed when the event occurs


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The onload event is supported in all major browsers.


onload is Supported by the Following HTML Tags:

<body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>


Examples

Try it Yourself - Examples

onload on <img>
Alert "Image is loaded" immediately after an image has been loaded.


Event Object Reference Event Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook