- Notifications
You must be signed in to change notification settings - Fork1
Cross-browser method of adding DOMContentLoaded events.
License
jesseskinner/addDOMLoadEvent
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Cross-browser method of adding DOMContentLoaded events.
To use: call addDOMLoadEvent one or more times with functions, ie:
function something() { // do something}addDOMLoadEvent(something);addDOMLoadEvent(function() { // do other stuff});Original blog post (Jesse Skinner, June 2006):http://www.thefutureoftheweb.com/blog/adddomloadevent
There has been a problem with using window.onload in JavaScript. This event handler waits until all the images and other files load before executing. If you need some JavaScript to execute when the page loads, you usually only need the HTML to be downloaded, not all the images.
The event to use for this is "DOMContentLoaded", but only Firefox (and recently, Opera 9) support this. There are different ways to do this in every other browser, and people have been working on finding a complete solution to this for some time.
Very recently, this problemhas been solved by Dean Edwards, Matthias Miller and John Resig. There is a unique solution for Internet Explorer, Safari, and for W3C-compatible browsers (Firefox and Opera 9).
Very soon after, Dan Webb adapted the solution to prototype. Unlike the original solution, this code allows you to add more than one function to be executed when the DOM loads.
Inspired bySimon Willison's addLoadEvent function, I wanted to create a standalone generic solution that anyone could use without needing a specific framework.
About
Cross-browser method of adding DOMContentLoaded events.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.