Hi, I do think rather than trying to jig around with the order of the various things in the file, you'd be better off using a dom:loaded handler to hook up your events, rather than using DOM0-style "onload=" statements in the tags. Not only is this a better separation of concerns, but it will tend to be more reliable as you don't have to worry about the order of things.
For instance, I'm not sure what your showImage() function does, but you can do something like this (untested, probably over-verbose): * * * * document.observe("dom:loaded", hookThingsUp); function hookThingsUp() { showImageWhenReady('theimg'); } function showImageWhenReady(imgid) { var img; img = $(imgid); img.observe('loaded', imageReadyHandler); showImageIfReady(img); } function showImageIfReady(img) { if (img.complete && !img._shown) { img._shown = true; img.stopObserving('loaded', imageReadyHandler); showImage(img); } } function onImageReadyHandler(evt) { showImageIfReady(evt.element()); } * * * * That looks like a lot of code (and I wouldn't be surprised if it could be shortened), but the basic points are: * Hook up the event once the DOM is loaded, none of this DOM0 stuff. * Since at that point the image may _already_ be ready, check for that. * Disconnect the event when the image is complete and you show it. * Be aware of the race condition when hooking up the event handler, and handle it (by explicitly calling showImageIfReady and flagging whether we've shown it). Hope this helps, -- T.J. Crowder tj / crowder software / com On Apr 25, 11:28 pm, liketofindoutwhy <[EMAIL PROTECTED]> wrote: > On Apr 25, 2:58 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > > > > Would somebody know that why if the 1st and 2nd line is swapped, then > > > Firefox 2 and IE 7 will not run... > > > As Justin said, if it loads fast enough (such as from cache), the > > event will get fired before your doc has been fully loaded and before > > the script exists. Remember that unless you use a load handler > > (either window.onload or Prototype's own "dom:loaded" events), things > > early in the page can happen before the page as a whole exists in the > > browser. > > Thanks very much. When the pic loads fast enough, and say the > javascript code is at the beginning, it could fire off showMe() and > then the function will use the element with id="display". There is > also a chance that the element id="display" is not loaded yet... so > in that case, will i need to move the element above the showMe() > code? that probably is not a good idea to rearrange element according > to javascript... > > by the way, so only <img> and <body> can have onload? can't I have a > <div> and use an onload to mean when everything inside of it gets > rendered, such as text and img. > > Thank you guys. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---