Display 'loading' message when scripts are executed and page is stillloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicolas R

    Display 'loading' message when scripts are executed and page is stillloading

    Hi all,
    Im trying to figure out how to display a 'loading' message when
    scripts are being executed, ie when the page is still not ready for
    interaction. This is for a web app which relies on javascript to
    insert dom elements and do stuff, so the user must know when
    everything is ready to interact with.

    I tried using an interval which checks for a specific variable
    (page_loading) and when its set to false then the 'loading' message is
    removed (its appended on page load). This requires that I set the
    variable to true at the start of each of my functions (at least the
    most time consuming ones) and setting it to false at the end. Even so,
    its not very reliable and its not a pretty solution.

    Is there a way to set an interval which checks whether or not a
    function is currently being executed, or something similar?

    Has anyone figured this out?

    Cheers
  • GArlington

    #2
    Re: Display 'loading' message when scripts are executed and page isstill loading

    On Apr 30, 10:04 am, Nicolas R <ruda...@google mail.comwrote:
    Hi all,
    Im trying to figure out how to display a 'loading' message when
    scripts are being executed, ie when the page is still not ready for
    interaction. This is for a web app which relies on javascript to
    insert dom elements and do stuff, so the user must know when
    everything is ready to interact with.
    >
    I tried using an interval which checks for a specific variable
    (page_loading) and when its set to false then the 'loading' message is
    removed (its appended on page load). This requires that I set the
    variable to true at the start of each of my functions (at least the
    most time consuming ones) and setting it to false at the end. Even so,
    its not very reliable and its not a pretty solution.
    >
    Is there a way to set an interval which checks whether or not a
    function is currently being executed, or something similar?
    >
    Has anyone figured this out?
    >
    Cheers
    You can set a div innerHTML to say something like "Loading... " and
    position this div anywhere you want on the page.
    Show it when any script starts executing (first executable line) and
    hide that div in the end of your script (last executable line)...

    Comment

    • Tom de Neef

      #3
      Re: Display 'loading' message when scripts are executed and page is still loading

      "GArlington " <garlington@tis cali.co.ukwrote :
      >Hi all,
      >Im trying to figure out how to display a 'loading' message when
      >scripts are being executed, ie when the page is still not ready for
      >interaction. This is for a web app which relies on javascript to
      >insert dom elements and do stuff, so the user must know when
      >everything is ready to interact with.
      >>
      >
      You can set a div innerHTML to say something like "Loading... " and
      position this div anywhere you want on the page.
      Show it when any script starts executing (first executable line) and
      hide that div in the end of your script (last executable line)...
      Maybe better: put the '<div id=loading>Load ing ...</div>' in the html
      source. It will display then for sure.
      Put all the js initialization code in <body onload=initiali ze()and remove
      the <div id=loadingin the last statement of this initialization.
      Tom


      Comment

      • Henry

        #4
        Re: Display 'loading' message when scripts are executed and page isstill loading

        On Apr 30, 10:04 am, Nicolas R wrote:
        <snip>
        Is there a way to set an interval which checks whether
        or not a function is currently being executed,
        It is absolutely impossible for javascript to execute a test that will
        determine whether other javascript in the same environment is
        executing because javascript is single-threaded so if the other
        javascript is executing the 'test' will not be, and if the test is
        executing the subject of the 'test' cannot be.
        or something similar?
        Insufficient context!

        Comment

        • Nicolas R

          #5
          Re: Display 'loading' message when scripts are executed and page isstill loading

          Thank you all for your replies.

          GArlington: that's what I do now and since I have quite a few
          functions this becomes a bit messy.

          Tom: if I only hide/show the 'loading' message from the primary init
          function then it hides too quickly, as some of my functions rely on
          timeouts and ajax requests to get/display content.

          Henry: yes I am aware of this, and that's why I was considering using
          a timer but even so you say that there's no internal javascript
          functionality that checks whether or not a function is being executed?

          The script I have currently works more or less like this:
          1) user loads page
          2) another page is loaded on iframe
          3) when the iframe page loads, I insert some styles and scripts to its
          head
          4) when the scripts are loaded (I check for a specific function, using
          typeof and a timer), I execute them
          5) using ajax, I request some content from another page
          6) when the ajax request is done, I insert that content to the parent
          page
          7) finally i attach some events on a few forms (submit etc)

          So even though I can know when the iframe page is ready, when any
          scripts are being loaded, and when any ajax requests are completed, I
          am looking for a way to know when all my other functions (mostly loops
          and setting/getting variables and dom elements) are being executed.

          Cheers

          Comment

          Working...