Such a command as 'onbeforeload'?

Discussion in 'HTML' started by CJS, Nov 14, 2007.

  1. CJS

    CJS Guest

    Hi, I have a javascript popup which I want to happen BEFORE the rest of the
    page loads. It's something for people to read while quite a heavy page
    loads behind it.

    I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    doesn't pop up at all then.

    Any ideas?

    Thanks.
     
    CJS, Nov 14, 2007
    #1
    1. Advertising

  2. On Nov 14, 2:33 pm, "CJS" <> wrote:
    > Hi, I have a javascript popup which I want to happen BEFORE the rest of the
    > page loads. It's something for people to read while quite a heavy page
    > loads behind it.
    >
    > I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    > doesn't pop up at all then.


    I didn't see such an event. But what are you trying to accomplish?
    Perhaps there is a way to do what you require via another path.
     
    nolo contendere, Nov 14, 2007
    #2
    1. Advertising

  3. On Nov 14, 2:48 pm, nolo contendere <> wrote:
    > On Nov 14, 2:33 pm, "CJS" <> wrote:
    >
    > > Hi, I have a javascript popup which I want to happen BEFORE the rest of the
    > > page loads. It's something for people to read while quite a heavy page
    > > loads behind it.

    >
    > > I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    > > doesn't pop up at all then.

    >
    > I didn't see such an event. But what are you trying to accomplish?
    > Perhaps there is a way to do what you require via another path.


    This is untested, but may serve your needs.

    http://www.codingforums.com/showthread.php?s=&threadid=15203
     
    nolo contendere, Nov 14, 2007
    #3
  4. CJS wrote:
    > Hi, I have a javascript popup which I want to happen BEFORE the rest of the
    > page loads. It's something for people to read while quite a heavy page
    > loads behind it.


    If it is a popup window, it will be blocked. If it is something else,
    loading it will only slow down or prevent loading of the other, more
    important content; if it even works.

    In any case, it is nothing that can be recommended. BTDT. You are far
    better off with either reducing the size of the "heavy page", for example by
    splitting it into several documents, and/or with structuring it better (for
    example by avoiding layout tables in favor of CSS-positioned blocks) so that
    the user can read the main content while it is loading.


    F'up2 comp.lang.javascript

    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Nov 14, 2007
    #4
  5. On Nov 14, 2:33 pm, "CJS" <> wrote:
    > Hi, I have a javascript popup which I want to happen BEFORE the rest of the
    > page loads. It's something for people to read while quite a heavy page
    > loads behind it.
    >
    > I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    > doesn't pop up at all then.
    >
    > Any ideas?
    >


    You could start off by showing a loader of some sort (image, txt,
    whatever) in a div (style="display: block;"), with your content in a
    div (style="display: none;"), and onload, call a function that sets
    the loader div to display: none and the content div to display: block.
     
    nolo contendere, Nov 14, 2007
    #5
  6. CJS

    CJS Guest

    "nolo contendere" <> wrote in message
    news:...
    > On Nov 14, 2:33 pm, "CJS" <> wrote:
    >> Hi, I have a javascript popup which I want to happen BEFORE the rest of
    >> the
    >> page loads. It's something for people to read while quite a heavy page
    >> loads behind it.
    >>
    >> I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    >> doesn't pop up at all then.

    >
    > I didn't see such an event. But what are you trying to accomplish?
    > Perhaps there is a way to do what you require via another path.


    Simply what I want to accomplish is the popup to come up *first* befoer any
    other page elements load. It is complicated as to why, and other factors,
    but that is what needs to happen.

    The onload tag seems to open happen after the page has finished loading
    completely, which is odd.
     
    CJS, Nov 15, 2007
    #6
  7. CJS

    CJS Guest

    "nolo contendere" <> wrote in message
    news:...
    > On Nov 14, 2:48 pm, nolo contendere <> wrote:
    >> On Nov 14, 2:33 pm, "CJS" <> wrote:
    >>
    >> > Hi, I have a javascript popup which I want to happen BEFORE the rest of
    >> > the
    >> > page loads. It's something for people to read while quite a heavy page
    >> > loads behind it.

    >>
    >> > I tried using 'onbeforeload' instead of 'onload' in the Body tag, but
    >> > it
    >> > doesn't pop up at all then.

    >>
    >> I didn't see such an event. But what are you trying to accomplish?
    >> Perhaps there is a way to do what you require via another path.

    >
    > This is untested, but may serve your needs.
    >
    > http://www.codingforums.com/showthread.php?s=&threadid=15203


    Thanks but that is not related to my request above to have a JS popup happen
    as the first event before any other loading takes place.
     
    CJS, Nov 15, 2007
    #7
  8. CJS

    Randy Webb Guest

    CJS said the following on 11/15/2007 4:44 AM:

    [follow-up set to comp.lang.javascript]

    > "nolo contendere" <> wrote in message
    > news:...
    >> On Nov 14, 2:33 pm, "CJS" <> wrote:
    >>> Hi, I have a javascript popup which I want to happen BEFORE the rest of
    >>> the
    >>> page loads. It's something for people to read while quite a heavy page
    >>> loads behind it.
    >>>
    >>> I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    >>> doesn't pop up at all then.

    >> I didn't see such an event. But what are you trying to accomplish?
    >> Perhaps there is a way to do what you require via another path.

    >
    > Simply what I want to accomplish is the popup to come up *first* befoer any
    > other page elements load. It is complicated as to why, and other factors,
    > but that is what needs to happen.
    >
    > The onload tag seems to open happen after the page has finished loading
    > completely, which is odd.


    Want something to happen during load? Don't use onload. It fires after
    the element has completely loaded. Why you would find it odd that an
    event that is defined to trigger after the element is completely loaded
    only fires after the element is completely loaded is, well, odd to say
    the least.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?
     
    Randy Webb, Nov 15, 2007
    #8
  9. On Nov 15, 5:44 am, "CJS" <> wrote:
    > "nolo contendere" <> wrote in message
    >
    > news:...
    >
    > > On Nov 14, 2:33 pm, "CJS" <> wrote:
    > >> Hi, I have a javascript popup which I want to happen BEFORE the rest of
    > >> the
    > >> page loads. It's something for people to read while quite a heavy page
    > >> loads behind it.

    >
    > >> I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    > >> doesn't pop up at all then.

    >
    > > I didn't see such an event. But what are you trying to accomplish?
    > > Perhaps there is a way to do what you require via another path.

    >
    > Simply what I want to accomplish is the popup to come up *first* befoer any
    > other page elements load. It is complicated as to why, and other factors,
    > but that is what needs to happen.
    >
    > The onload tag seems to open happen after the page has finished loading
    > completely, which is odd.


    Hmm, a friend of mine uses the technique I mentioned and it works
    fine. Have you tried the <div> swapping thing? It is precisely
    *because* the onload happens *after* the page has loaded that you can
    use that as the event to trigger the <div> display swap.

    And while the page is in the process of loading, the onload event has
    not fired yet, but the loader div is being displayed. I realize that
    this doesn't give you the popup you requested, but it serves as a
    solution to your ultimate goal of providing the user with feedback
    that a heavy page is loading.

    HTH
     
    nolo contendere, Nov 15, 2007
    #9
  10. On Nov 15, 5:44 am, "CJS" <> wrote:
    > "nolo contendere" <> wrote in message
    >
    > news:...
    >
    > > On Nov 14, 2:33 pm, "CJS" <> wrote:
    > >> Hi, I have a javascript popup which I want to happen BEFORE the rest of
    > >> the
    > >> page loads. It's something for people to read while quite a heavy page
    > >> loads behind it.

    >
    > >> I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    > >> doesn't pop up at all then.

    >
    > > I didn't see such an event. But what are you trying to accomplish?
    > > Perhaps there is a way to do what you require via another path.

    >
    > Simply what I want to accomplish is the popup to come up *first* befoer any
    > other page elements load. It is complicated as to why, and other factors,
    > but that is what needs to happen.
    >
    > The onload tag seems to open happen after the page has finished loading
    > completely, which is odd.


    Try something like this:

    <html>
    <head>
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript">
    function kill_loader() {
    $('loader').style.display = 'none';
    $('contents').style.display = 'block';
    }
    </script>
    </head>
    <body onload="kill_loader();">
    <div id=loader style="display: block; overflow: auto; valign: middle;
    text-align: center; background-color: #fff; width: 100%; height:
    100%;">
    <img src="images/spinner.gif" />
    </div>
    <div id=contents style="display: none;">hi there</div>
    </body>
    </html>
     
    nolo contendere, Nov 15, 2007
    #10
  11. nolo contendere meinte:

    > <html>
    > <head>
    > <script type="text/javascript" src="js/prototype.js"></script>
    > <script type="text/javascript">
    > function kill_loader() {
    > $('loader').style.display = 'none';
    > $('contents').style.display = 'block';
    > }


    Prototype just to get rid off document.getElementById()? I suppose it 'd
    more helpful for the OP, if he could get the plain JS version, hence

    document.getElementById('loader').style.display = 'none';
    document.getElementById('contents').style.display = 'block';


    Gregor


    --
    http://www.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://www.licht-blick.at ::: Forum für Multivisionsvorträge
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Nov 15, 2007
    #11
  12. On Nov 15, 11:51 am, Gregor Kofler <> wrote:
    > nolo contendere meinte:
    >
    > > <html>
    > > <head>
    > > <script type="text/javascript" src="js/prototype.js"></script>
    > > <script type="text/javascript">
    > > function kill_loader() {
    > > $('loader').style.display = 'none';
    > > $('contents').style.display = 'block';
    > > }

    >
    > Prototype just to get rid off document.getElementById()? I suppose it 'd
    > more helpful for the OP, if he could get the plain JS version, hence
    >
    > document.getElementById('loader').style.display = 'none';
    > document.getElementById('contents').style.display = 'block';



    heh, thanks.
     
    nolo contendere, Nov 15, 2007
    #12
  13. nolo contendere wrote:
    > On Nov 15, 5:44 am, "CJS" <> wrote:
    >> "nolo contendere" <> wrote in message
    >>
    >> news:...
    >>
    >>> On Nov 14, 2:33 pm, "CJS" <> wrote:
    >>>> Hi, I have a javascript popup which I want to happen BEFORE the rest of
    >>>> the
    >>>> page loads. It's something for people to read while quite a heavy page
    >>>> loads behind it.
    >>>> I tried using 'onbeforeload' instead of 'onload' in the Body tag, but it
    >>>> doesn't pop up at all then.
    >>> I didn't see such an event. But what are you trying to accomplish?
    >>> Perhaps there is a way to do what you require via another path.

    >> Simply what I want to accomplish is the popup to come up *first* befoer any
    >> other page elements load. It is complicated as to why, and other factors,
    >> but that is what needs to happen.
    >>
    >> The onload tag seems to open happen after the page has finished loading
    >> completely, which is odd.

    >
    > Try something like this:
    >

    <snip code>

    If the initial page takes so long to load that you need an progress
    indicator, then maybe you need to reevaluate the content of your page
    and break it up into more manageable size bits...

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Nov 15, 2007
    #13
  14. CJS wrote:


    > Simply what I want to accomplish is the popup to come up *first* befoer
    > any other page elements load. It is complicated as to why, and other
    > factors, but that is what needs to happen.


    Something very simple that works in most browsers:
    Put a script at the top of your document, in the HEAD.
    It will typically be executed as soon as the browser parses it, and before
    the document is entirely loaded.

    >
    > The onload tag seems to open happen after the page has finished loading
    > completely, which is odd.


    No, it isn't odd. The onload function is EXACTLY for that. It ensures that
    the DOM is complete.



    --
    If you've a question that doesn't belong to Usenet, contact me at
    <>
     
    André Gillibert, Nov 17, 2007
    #14
  15. nolo contendere wrote:


    > And while the page is in the process of loading, the onload event has
    > not fired yet, but the loader div is being displayed. I realize that
    > this doesn't give you the popup you requested, but it serves as a
    > solution to your ultimate goal of providing the user with feedback
    > that a heavy page is loading.
    >


    No, it's rather REMOVING feedback during page loading.

    The only thing that the user knows is: Something is loading or frozen due
    to a buggy JavaScript (very common) or JavaScript disabled or a connection
    problem (e.g. an element of the page for which the connection has been
    closed by the server but the user agent didn't notice that).

    With progressive rendering, you see exactly what's loading as it's
    displayed.

    I also noticed that some sites containing this awful hack, the loading of
    the entire page becomes much slower (e.g. 14 or 15 seconds instead of 2 or
    3) because all the tiny useless icons advertisements and 1x1 images (e.g.
    to do some cr*ppy statistics) at the bottom of a site require much time to
    be loaded.

    If you hate progressive rendering, please, don't harm MY computer, simply
    disable progressive rendering in YOUR browser.
    e.g. with Opera go to Tools->Preferences->Advanced->Browsing->Loading and
    check "Redraw when loaded".

    As a general solution, write a little HTTP proxy application that disable
    progressive rendering. But, please, use it for personal use.

    --
    If you've a question that doesn't belong to Usenet, contact me at
    <>
     
    André Gillibert, Nov 17, 2007
    #15
    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. San Diego Guy
    Replies:
    0
    Views:
    584
    San Diego Guy
    Aug 7, 2003
  2. Lucas Cowald
    Replies:
    4
    Views:
    1,139
    Tohid
    Oct 23, 2003
  3. Bernd Oninger
    Replies:
    1
    Views:
    842
    Martin Honnen
    Jul 7, 2004
  4. PerlFAQ Server
    Replies:
    0
    Views:
    139
    PerlFAQ Server
    Apr 20, 2011
  5. CJS

    Such a command as 'onbeforeload'?

    CJS, Nov 14, 2007, in forum: Javascript
    Replies:
    18
    Views:
    167
    André Gillibert
    Nov 17, 2007
Loading...

Share This Page