467,219 Members | 1,221 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,219 developers. It's quick & easy.

body onLoad - what does it do ?


Hello.

I've got a page with sound through a swf file, working with an animation
with preloaded JPEG files (animated through use of setTimeout).

I'm preloading the JPEG files through Javascript in the <head> tag, the
Flash animation/sound file being in the <object> & <embed> tags.

I'd like to fire the sound and JPEG animation once everything is loaded :
the page content, the JPEG files (stored in an array), and the swf file.

My question is : how does the onLoad body tag work ? I know it
covers the document content itself, probably the Flash animation, but
does it cover the preloaded image files stored through Javascript ?

I've found no clear answer on this. Thanks for replying.

--

Je suis le ciel, je suis la mer,
Je suis les mirages du désert,
Je suis ta dernière image avant de mourir,
Je suis ta ville imaginaire.

Je suis ce qui a été, ce qui est et ce qui sera,
Et quand je partirai tout partira avec moi.

Je suis Dieu, je ne suis rien,
Je suis Simbabbad de Batbad !

Emmanuel Papillon - http://www.batbad.com
Jul 23 '05 #1
  • viewed: 3245
Share:
5 Replies
On Tue, 27 Apr 2004 01:05:23 +0200, Emmanuel Papillon
<em******@diespamdie.com> wrote:

[snip]
My question is : how does the onLoad body tag work ?
You mean the load (or onload) intrinsic event in the BODY element?
I know it covers the document content itself, probably the Flash
animation, but does it cover the preloaded image files stored through
Javascript ?

I've found no clear answer on this. [...]


Probably because there isn't one. The load intrinsic event is defined as
firing "when the user agent finishes loading a window or all frames within
a FRAMESET." This tends to be interpreted differently by each browser
manufacturer. Some will fire when the document (the HTML) has been parsed
completely. Some when the HTML and all images are loaded. Some may extend
it to all objects and applets.

About the only thing you can probably anticipate is that the load event
won't wait for your preloading script. The script will certainly have
started, but it probably won't have finished unless there is little to
preload, or the user has a very fast connection.

[snip]

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
Michael Winter wrote:
[snip]
About the only thing you can probably anticipate is that the load event
won't wait for your preloading script. The script will certainly have
started, but it probably won't have finished unless there is little to
preload, or the user has a very fast connection.


I do not think this is completely correct. Scripts are executed
serially. The script that does the preloading will be executed
completely before an onLoad event occurs. Only if a script is using
setTimeout or the DEFER attribute, will this not be the case.

The OP states that he uses setTimeout for animation of the images, and
not for preloading.

There is one issue with this... Just because the script has executed
completely, does not mean that the image has been loaded. When you make
a request of any type, the request is not guaranteed to happen
immediately. So, creating a new image, and setting the SRC attribute
will request that the browser load the image. This can take a long
time, so the assignemnt returns immediately, and the script may continue
to execute. So, when the onLoad happens, you can be pretty sure that
the script has executed, but there is no guarantee that the images have
been loaded yet.

Brian

Jul 23 '05 #3
On Tue, 27 Apr 2004 07:22:56 -0400, Brian Genisio <Br**********@yahoo.com>
wrote:
Michael Winter wrote:
[snip]
About the only thing you can probably anticipate is that the load event
won't wait for your preloading script. The script will certainly have
started, but it probably won't have finished unless there is little to
preload, or the user has a very fast connection.
I do not think this is completely correct. Scripts are executed
serially. The script that does the preloading will be executed
completely before an onLoad event occurs. Only if a script is using
setTimeout or the DEFER attribute, will this not be the case.


[snip]

I meant total execution of the script which would include its side-effects
- in this case, the loading of images. From what I've observed, if a
script is present in the HEAD of a document, the BODY won't have even
begun parsing until that script has executed...
There is one issue with this... Just because the script has executed
completely, does not mean that the image has been loaded. When you make
a request of any type, the request is not guaranteed to happen
immediately. So, creating a new image, and setting the SRC attribute
will request that the browser load the image. This can take a long
time, so the assignemnt returns immediately, and the script may continue
to execute. So, when the onLoad happens, you can be pretty sure that
the script has executed, but there is no guarantee that the images have
been loaded yet.


....so I totally agree with what you're saying: the script will have
executed (the browser will wait that long), but will probably not have
"finished".

My apologies for not being clear,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
The OP states that he uses setTimeout for animation of the images, and
not for preloading.


The setTimeout instructions fire only after the onLoad event.

The loading function in the <head> is something like :

--

function initialise_tableau(tableau,img_nb,nom_img)
{
for (i=0;i<=img_nb-1;i++)
{
tableau[i]=new Image;
tableau[i].src=nom_img + (i+1) + ".jpg";
}
}

initialise_tableau(tableau_levier,nb_img,"levier_" );

--

The launching function is something like :

--

function subst_etape()
{
document.LEVIER.src=tableau_levier[etape].src;

if(etape<=nb_img-2) etape++;

return true;
}

function LEVIER_JOURNEY()
{
for (i=0;i<=nb_img-1;i++)
{
setTimeout('subst_etape()',i*(latence-i));
}

return true;
}

--

And it fires with :

--

<body bgcolor="#121212" onLoad="document.levier_swf.Play()">

--

... the Flash file triggering LEVIER_JOURNEY() through FScommand once fired.

My question is : is the onLoad event working for :

1) The HTML page code (obviously yes)

2) The page HTML body content

3) The Flash file

4) The preloaded images in the header

Thanks.
Jul 23 '05 #5

"Emmanuel Papillon" <em******@diespamdie.com> a écrit dans le message de news:c6**********@news-reader2.wanadoo.fr...
My question is : is the onLoad event working for :

1) The HTML page code (obviously yes)

2) The page HTML body content

3) The Flash file

4) The preloaded images in the header

Thanks.


Never mind. I made some simple test renaming files with a wrong name
so that the Flash animation or the preloaded images never finish loading.

For those interested, here's my results :

3) IE : yes, NS : no

4) IE : no, NS : no

Guess I won't trust onLoad on this and do my own checking !

:-)

Thanks to those who answered.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by laredotornado@zipmail.com | last post: by
5 posts views Thread by Patient Guy | last post: by
2 posts views Thread by Earl Teigrob | last post: by
5 posts views Thread by tuxedo | last post: by
5 posts views Thread by mazdotnet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.