body onLoad - what does it do ?

Discussion in 'Javascript' started by Emmanuel Papillon, Apr 27, 2004.

  1. 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
    Emmanuel Papillon, Apr 27, 2004
    #1
    1. Advertising

  2. On Tue, 27 Apr 2004 01:05:23 +0200, Emmanuel Papillon
    <> 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
    d (replace ".invalid" with ".uk" to reply)
    Michael Winter, Apr 27, 2004
    #2
    1. Advertising

  3. 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
    Brian Genisio, Apr 27, 2004
    #3
  4. On Tue, 27 Apr 2004 07:22:56 -0400, Brian Genisio <>
    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
    d (replace ".invalid" with ".uk" to reply)
    Michael Winter, Apr 27, 2004
    #4

  5. > 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=new Image;
    tableau.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.
    Emmanuel Papillon, Apr 27, 2004
    #5
  6. "Emmanuel Papillon" <> a écrit dans le message de news:c6lp6d$6ei$...

    > 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.
    Emmanuel Papillon, Apr 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabio R.
    Replies:
    0
    Views:
    768
    Fabio R.
    Mar 25, 2005
  2. =?Utf-8?B?Q2FsdmluIEtE?=

    <body onload="alert('Hello');"> does not work! Why?

    =?Utf-8?B?Q2FsdmluIEtE?=, Aug 25, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    10,388
    =?Utf-8?B?Q2FsdmluIEtE?=
    Aug 29, 2005
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    522
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    5
    Views:
    240
    Thomas 'PointedEars' Lahn
    May 15, 2005
  5. Replies:
    0
    Views:
    161
Loading...

Share This Page