admin管理员组

文章数量:1316008

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?

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?

Share Improve this question edited Jun 22, 2021 at 20:14 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 23, 2010 at 2:39 PaulPaul 1,01421 silver badges35 bronze badges 2
  • 1 Is 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 Commented Jul 23, 2010 at 3:29
  • 2 similar question stackoverflow./questions/282245/… – Aaron Saunders Commented Jul 23, 2010 at 3:50
Add a ment  | 

3 Answers 3

Reset to default 5

If you're looking to invoke an event handler before onload, DOMContentLoaded is one event that usually fires before.

document.addEventListener('DOMContentLoaded', functionRef, false);

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.

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]

https://web.archive/web/20090131201912/http://dean.edwards.name:80/weblog/2005/02/order-of-events/

本文标签: javascriptWhat39s the first event fired when a web page is loaded to the browserStack Overflow