24
votes

Possible Duplicate:
Difference between DOMContentLoaded and Load events

Whats the difference between

window.addEventListener("load", load, false);

and

document.addEventListener("DOMContentLoaded", load, false);

?

2
you may find answer stackoverflow.com/questions/2414750/… Fired on a Window object when a document's DOM content is finished loading, but unlike "load", does not wait until all images are loaded.Fedor Skrynnikov

2 Answers

38
votes
  • DOMContentLoaded - the whole document (HTML) has been loaded.
  • load - the whole document and its resources (e.g. images, iframes, scripts) have been loaded.
8
votes

DOMContentLoaded awaits only for HTML and scripts to be loaded.
window.onload and iframe.onload triggers when the page is fully loaded with all dependent resources including images and styles.

Here is more details you can find http://javascript.info/tutorial/onload-ondomcontentloaded