By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,630 Members | 1,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,630 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Apr 30, 10:04 am, Nicolas R <ruda...@googlemail.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)...
Jun 27 '08 #2

P: n/a
"GArlington" <ga********@tiscali.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>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=loadingin the last statement of this initialization.
Tom
Jun 27 '08 #3

P: n/a
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!
Jun 27 '08 #4

P: n/a
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
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.