onloadEvent

事件对象参考手册Event Object

Examples

Execute JavaScript code after the page has finished loading:

<body onload="myFunction()">

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

Definition and Usage

The onload event occurs immediately after a page or an image has finished loading.

onload is commonly used on the <body> element to execute script code after the page has fully loaded (including images, CSS files, etc.).

Syntax

In HTML:

<body onload="SomeJavaScriptCode">

In JavaScript:

window.onload=function(){SomeJavaScriptCode};

Parameters Description
SomeJavaScriptCode Required. Specifies the JavaScript to execute when the event occurs.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onload event.


The following HTML tags support onload:

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


实例

More Examples

Using onload in <img>
Pop up "Image is loaded" immediately after the image is loaded.


事件对象参考手册Event Object Other Extensions