What is the difference between DOMContentLoaded
and load
events?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
From the Mozilla Developer Center:
DOMContentLoaded
==window.onDomReady()
Load
==window.onLoad()
See: http://learn.jquery.com/using-jquery-core/document-ready/
See the difference yourself:
DEMO
From Microsoft IE
From Mozilla Developer Network
The
DOMContentLoaded
event will fire as soon as the DOM hierarchy has been fully constructed, theload
event will do it when all the images and sub-frames have finished loading.DOMContentLoaded
will work on most modern browsers,but not on IEincluding IE9 and above. There are some workarounds to mimic this event on older versions of IE, like the used on the jQuery library, they attach the IE specificonreadystatechange
event.domContentLoaded: marks the point when both the DOM is ready and there are no stylesheets that are blocking JavaScript execution - meaning we can now (potentially) construct the render tree. Many JavaScript frameworks wait for this event before they start executing their own logic. For this reason the browser captures the EventStart and EventEnd timestamps to allow us to track how long this execution took.
loadEvent: as a final step in every page load the browser fires an “onload” event which can trigger additional application logic.
source