As asked in the title, what's the first event fired when a web page is loaded to the browser? I believe there are events before window.onload
. What are they, and which one is the first fired?
Asked
Active
Viewed 4,806 times
7

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Paul
- 954
- 19
- 34
-
1Is this a trivia question, do you generally want to run some code before `onload`, or do you want to run some code at some specific point before `onload`? – deceze Jul 23 '10 at 03:29
-
2similar question http://stackoverflow.com/questions/282245/what-is-the-event-precedence-in-javascript – Aaron Saunders Jul 23 '10 at 03:50
3 Answers
4
If you're looking to invoke an event handler before onload
, DOMContentLoaded
is one event that usually fires before.
document.addEventListener('DOMContentLoaded', functionRef, false);

meder omuraliev
- 183,342
- 71
- 393
- 434
0
Don't know if this helps but firebug/IE Dev Tool is really good for watching JS events execute as the page loads. I use that to caputre events and see the order of how they're happening.

Mike Sav
- 14,805
- 31
- 98
- 143
0
This looks to have some of what you're looking for:
[Updated link - link-rot - this is why you copy and paste essential information directly into an answer]

Michael Mullany
- 30,283
- 6
- 81
- 105

Tom Winter
- 1,813
- 3
- 18
- 23