The onload property of the GlobalEventHandlers mixin is an EventHandler that processes load events on a Window, XMLHttpRequest, <img> element, etc.

The load event fires when a given resource has loaded.


target.onload = functionRef;


functionRef is the handler function to be called when the window’s load event fires.


window.onload = function() {
<!doctype html>
    <title>onload test</title>
    // ES5
      function load() {
        console.log("load event detected!");
      window.onload = load;
    // ES2015
      const load = () => {
        console.log("load event detected!");
      window.onload = load;
    <p>The load event fires when the document has finished loading!</p>


The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.

There are also DOM Events like DOMContentLoaded and DOMFrameContentLoaded (which can be handled using EventTarget.addEventListener()) which are fired after the DOM for the page has been constructed, but do not wait for other resources to finish loading.


Specification Status Comment
HTML Living Standard
The definition of 'onload' in that specification.
Living Standard Initial definition

Browser compatibility

BCD tables only load in the browser

See also