473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Small javascript/html that's not working as I think it should - please help

I have a small javascript/html code below that demonstrates that
problem I'm having in a larger program. I've tried all kinds of things
to get it to work, but it just won't do what I want. I've tried
setTimeout, setInterval. In this dumb, but valid example, i want to
display an iframe that loads google. Before it loads I want to display
a 'processing' indicator in green in the middle of the window. Then,
when it is done, it is to turn off the indicator. What is happening is
that in the doit() function, the processing(true) statement doesn't
'appear' to run until after the iframe loads. Then it calls the
processing(false). So, the processing(true) and processing(false)
'seem' like they are back to back and you never see the 'processing'
message. Simple question, referencing the doit() function, how do I
show the 'processing' div, load the iframe, then hide the 'processing'
div. In my larger app, I'm not using iframes, but I am doing some ajax
stuff that takes some computing time on the server and I want the user
to know that it's doing something.

here is the code
----------------------------------
<html>
<script>
function processing( p_flag )
{
var v_processingIndicator = document.getElementById( 'Processing'
);
if( p_flag ) {
if( ! v_processingIndicator ) {
v_processingIndicator = document.createElement( "div" );
v_processingIndicator.id = 'Processing';
v_processingIndicator.style.position = 'absolute';
v_processingIndicator.style.width = '300px';
v_processingIndicator.style.left =
(document.body.clientWidth/2) - 150;
v_processingIndicator.style.top =
(document.body.clientHeight/2);
v_processingIndicator.style.zIndex = 10000;
v_processingIndicator.innerHTML =
"<center>Processing...</center>";
v_processingIndicator.style.visibility = 'hidden';
v_processingIndicator.style.background = 'lightgreen';
document.body.appendChild( v_processingIndicator );
}

v_processingIndicator.style.visibility = 'visible';
} else {
v_processingIndicator.style.visibility = 'hidden';
}
}

function doit()
{
processing( true );
document.getElementById( 'iframe' ).src = 'http://www.google.com';
processing( false );
}
</script>

<body>
<iframe id='iframe' width='600' height='200'></iframe>
</body>

<script>doit();</script>

</html>

-------------------------------
thanks in advance,
gkelly

Oct 26 '06 #1
1 1264
gk********@gmail.com wrote:
I have a small javascript/html code below that demonstrates that
problem I'm having in a larger program. I've tried all kinds of things
to get it to work, but it just won't do what I want. I've tried
setTimeout, setInterval. In this dumb, but valid example, i want to
display an iframe that loads google. Before it loads I want to display
a 'processing' indicator in green in the middle of the window. Then,
when it is done, it is to turn off the indicator. What is happening is
that in the doit() function, the processing(true) statement doesn't
'appear' to run until after the iframe loads.
Because most browsers will wait for the script to complete before
updating the screen, which is a good idea if you consider what it might
look like if you were doing lots of DOM manipluation in a script or
series of scripts.

Have your doIt() function use setTimeout() to call a function that
loads the page into the iFrame and attaches an onload function in the
iFrame that updates the "processing" mesage, e.g.:

function doit()
{
processing( true );
setTimeout(function(){
var iFrame = document.getElementById( 'iframe' )
iFrame.src = 'http://www.google.com';
iFrame.onload = function(){processing(false);}
},10);
}
--
Rob

Oct 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.