W3Schools.com

onload Event

Event Object Reference Event Object

Example

Execute a JavaScript immediately after a page has been loaded:

<body onload="load()">

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

Definition and Usage

The onload event occurs when an object has been loaded.

Syntax

In HTML:

<element onload="SomeJavaScriptCode">

In JavaScript:

object.onload="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>

onload is Supported by the Following JavaScript Objects:

Document, Window, XMLDocument, XMLHttpRequest


Examples

Try it Yourself - Examples

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


Event Object Reference Event Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE