Skip to main content
The standard is that the `load` event fires on `window`, not `document`, tho the latter often works
Source Link
Inigo
  • 14k
  • 5
  • 47
  • 79
documentwindow.addEventListener("load", function(){
    // ....
});
document.addEventListener("load", function(){
    // ....
});
window.addEventListener("load", function(){
    // ....
});
added another "right moment" option to the answer to make it even more complete.
Source Link
Inigo
  • 14k
  • 5
  • 47
  • 79

And if all of the above points are still to early...

What if you need your script to run after other scripts are run, including those scheduled to run at the very end (e.g. those scheduled for the "load" event)? See Run JavaScript after all window.onload scripts have completed?

What if you need to make sure your script runs after some other script, regardless of when it is run? This answer to the above question has that covered too.

And if all of the above points are still to early...

What if you need your script to run after other scripts are run, including those scheduled to run at the very end (e.g. those scheduled for the "load" event)? See Run JavaScript after all window.onload scripts have completed?

What if you need to make sure your script runs after some other script, regardless of when it is run? This answer to the above question has that covered too.

Small typo
Source Link
robstarbuck
  • 7.7k
  • 2
  • 45
  • 43

Event Listeners with radyStatesreadyStates - Alternative solution (readystatechange):

Event Listeners with radyStates - Alternative solution (readystatechange):

Event Listeners with readyStates - Alternative solution (readystatechange):

added 118 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
deleted 1 character in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
deleted 1 character in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 683 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 683 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 683 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 683 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 424 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 105 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 105 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 105 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
spelling
Source Link
Matthias Braun
  • 33.5k
  • 26
  • 150
  • 175
Loading
Typo fix
Source Link
Antonio Laguna
  • 9.2k
  • 7
  • 37
  • 72
Loading
Removed uneeded semicolon at the end of the last bit of code and a few characters from the divider line to allow the change
Source Link
Loading
Just spelling and typos to ease reading
Source Link
gyc
  • 4.3k
  • 6
  • 34
  • 55
Loading
Loading
added 29 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 177 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 706 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
added 706 characters in body
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading
Source Link
DevWL
  • 18.4k
  • 6
  • 96
  • 90
Loading