Richard Quadling
2007-Oct-18 08:40 UTC
Event.observe(window, ''load'', function() { ... }); vs document.observe(''dom:loaded'', function() { ... });
Hi. Just trying out Prototype V1.6.0rc1. Which is "better" of these observers? Event.observe(window, ''load'', function() { ... }); and document.observe(''dom:loaded'', function() { ... }); Currently I use the first one. Should I be changing to the second one for future proofing? Regards, Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Martin Ström
2007-Oct-18 12:15 UTC
Re: Event.observe(window, ''load'', function() { ... }); vs document.observe(''dom:loaded'', function() { ... });
It depends on what you want to do. If you''re only interesting in the DOM tree then dom:loaded if great since it doesn''t have to wait until all assets (like images, flash etc) are loaded before kicking in. But if you want to interact with the images and, let say, check their dimensions or something like that, its a good idea to let them load first. I often end up with one listener for the DOM (dom:loaded) which start listeners for DOM events since I want to do this as soon as possible (like hijack links) and another for the full document (window.onload) for things like...maybe fix png-images to work on IE6 Also, if you have scripts that will change the DOM in any way (like how many adsystem does with document.write) you might want to wait for window.unload before using the DOM tree too much, or at least test it carefully, but YMMV. Ciao Martin Sent from my computer On 18/10/2007, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Hi. > > Just trying out Prototype V1.6.0rc1. > > Which is "better" of these observers? > > Event.observe(window, ''load'', function() { ... }); > > and > > document.observe(''dom:loaded'', function() { ... }); > > Currently I use the first one. Should I be changing to the second one > for future proofing? > > Regards, > > Richard. > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---