the Future of the Web
  • Home
  • Articles
  • Contact
  • addDOMLoadEvent Revisited

    Aug 14 2007

    I've gone back and reworked addDOMLoadEvent. I got rid of the global variables and reduced the size down to 563 bytes!

    For the new script and the demo pages, check out addDOMLoadEvent.

    Update [Aug. 19, 2007]: Now the script preserves any existing window.onload function, and also executes functions instantly when called after the page has already loaded. But now the compressed version is a hefty 617 bytes.

    Tags: javascript adddomloadevent DOMContentLoaded domload
    View 4 Comments | Add a comment
  • Comments

    1. Ash at 9:10am on August 17, 2007

    Great script, something that the browsers should have supported natively in the first place.

    It works well in Firefox, but I'm facing some strange issues in IE.

    I tested the new compressed script in IE6 and it triggers a "document.getElementById() is null or not an object" error. The old uncompressed script doesn't return this error.

    Also, in both the scripts (old & new), the target function is called twice for some reason, and its not invoking the function after DOM load but rather after the images. So something is broken in IE6 I reckon. Any clues?

    Btw, I'm running IE 6.0.2900 on Windows XP SP2.

    2. Ash at 11:31am on August 17, 2007

    Adding to my previous msg: the above problems occur on a page with an iframe (Google Adsense Ad), if that help's diagnosing it.

    3. Jesse Skinner at 8:23am on August 19, 2007

    @Ash - I made some improvements to the script, test it out and see if it things are better. It now preserves the window.onload function. I didn't add the workaround for an iframe with setTimeout, because I'm worried it could create problems in some scenarios (it feels hacky as you admit and I don't know under what circumstances it'll become problematic).

    4. Daniel Hertz at 12:18pm on August 28, 2007

    Would it be possible to put the version (revision) numbers and dates in the code and on your blog? That way I know which version of addDOMLoadEvent I'm using.

    Thanks for sharing this JS with us...it's very helpful!

    Daniel Hertz, Founder
    Pixody.com

    Add a Comment

    Note: HTML tags and entities will be converted so that they are displayed as you type them. This means if you type in <em>, people will see <em>, and if you type &lt;em&gt;, people will see &lt;em&gt;.

  • Request a Quote

  • Jesse Skinner

    Jesse Skinner
    • About Me
    • Email Me
    • RSS Feed RSS Icon
    • @JesseSkinner
  • Recent Articles

    • jQuery Live Events
    • I need web developers
    • buttons need type="submit" to submit in IE
    • Win $200 in a Web Dev Writing Contest
    • Use Arrays in HTML Form Variables
    • 5 Reasons Freelancers Can Succeed in a Shrinking Economy
    • Keeping a Live Eye on Logs
    • Using PHP's empty() Instead of isset() and count()
    • Testing Web Pages with Lynx
    • Stop CSS Background Flickering in Internet Explorer 6
    • See All...
  • Categories

    • javascript (39)
    • links (21)
    • about (19)
    • web (14)
    • html (12)
    • server (11)
    • css (8)
    • browsers (8)
    • carnival (7)
    • work (6)
    • design (4)
    • seo (4)
    • ads (4)
    • standards (4)
    • events (4)
  • Older Articles

    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • September 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • April 2007
    • March 2007
    • February 2007
    • January 2007
    • December 2006
    • November 2006
    • October 2006
    • September 2006
    • August 2006
    • July 2006
    • June 2006
    • May 2006
    • April 2006
    • March 2006
    • February 2006
    • January 2006
    • December 2005
    • November 2005
    • October 2005
    • September 2005
    • August 2005
    • April 2005
    • See All...
Copyright © 2010 The Future of the Web