onload in JavaScript

https://www.w3schools.com/tags/ev_onload.asp

Example

Execute a JavaScript immediately after a page has been loaded:

<body onload="myFunction()">

Definition and Usage

The onload attribute fires 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.). However, it can be used on other elements as well (see "Supported HTML tags" below).

The onload attribute can be used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.

The onload attribute can also be used to deal with cookies (see "More Examples" below).

Supported HTML tags: <body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script> and <style>


原文地址:https://www.cnblogs.com/chucklu/p/11095752.html