I usually wrap my event listeners in a global event listener that fires
when the page has fully loaded.
Event.observe(window, 'load', function(event) {
// Place all element event listeners here
});
The problem with this is that it doesn't run until the page has fully
loaded (including downloading all images on the page).
More information on this is available at
http://www.prototypejs.org/api/event/observe
-Hector
sheps-ii wrote:
> Ok so Prototype effectively says that Javascript code anywhere in an
> HTML file is not cool, e.g. you should use observe to give HTML
> elements listeners which fire functions.
>
> But then where should the code start? Let me elaborate. Given the
> first assumption, I now have no javascript in my HTML save the files
> included in the <head>. But, for me to start JavaScript execution in
> one of these files is useless - if I try to use observe() then
> obviously the rest of the page hasn't loaded yet, and the script
> terminates.
>
> So how do people layout their code? Surely you have to have <body
> onload="..."> or something to let the Javascript know when it can fire
> away?
>
> Thanks in advance for all thoughts and advice.
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---