The domready event for Prototype
I've been a Mootools user for a while, but Prototype was a better fit for a project I was working on. Mootools adds thedomready event to the window object which fires when the DOM has finished loading. This is a lot nicer than window's built-in onload event which fires after everything has loaded including images, stylesheets, etc.
When I started with Prototype, I could not find the equivalent, and Google searches came up with other people's add-ons for Prototype to bring this functionality in. I tried a few that I found, and I couldn't get any to work reliably. I modified the best code I found, merging some ideas from Yahoo's YUI library and eventually got it working. The other day, however, I found that Prototype actually does have this already built-in; it's just that it's part of the document object, and has a different name: dom:loaded. To use it, you do:
Here's the link to Prototype's documentation on this.
Comments
this is exactly the solution I was looking for...prototype's built-in are much better that any add-ons - Yasel, Wednesday, May 20, 2009 Thanks for the tip! BTW, you have a typo in your example. It should be "dom:loaded" not "dom:ready". - Wesley Hather, Thursday, July 30, 2009 Thanks for the help. - Ivan dos Reis Andrade, Tuesday, December 29, 2009 @Wesley: Thanks for the update. At the time of writing, it was dom:ready, but it seems that they have since changed this to dom:loaded. - Patrick Gibson, Wednesday, December 30, 2009 dom:loaded and dom:ready has different meaning. dom:ready fires when all the dom nodes exist. dom:loaded fires when everything in the document is fully rendered, including images. This becomes extremely noticeable if you have large images loading in your page. But I don't think prototype has a built-in dom:ready method. - slebetman, Friday, January 8, 2010 @slebetman: Are you sure? From Prototype's documentation: "If you used window.onload before you might want to switch to dom:loaded because it will fire immediately after the HTML document is fully loaded, but before images on the page are fully loaded." - Patrick Gibson, Friday, January 15, 2010 |
Post a comment |
