Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
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.).
The onload event 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.
Here is an example of using the load
event. This is a method of the document object and is triggered when the page
loads. In this example, the function will display the current MONTH once the page loads.
// In HTML:
<element onload="myScript"></element>
// In JavaScript:
object.onload = function(){myScript};
// In JavaScript, using the addEventListener() method:
object.addEventListener("load", myScript);