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

N

Nicolas R

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
 
G

GArlington

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)...
 
T

Tom de Neef

GArlington said:
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>Loading ...</div>' in the html
source. It will display then for sure.
Put all the js initialization code in <body onload=initialize()> and remove
the <div id=loading> in the last statement of this initialization.
Tom
 
H

Henry

On Apr 30, 10:04 am, Nicolas R wrote:
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!
 
N

Nicolas R

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top