I have googled & I tried several answers but my problem is still occurring. I have a .net web page on IIS 7 and the code works fine in IE9 but not in Firefox. I need it to work in both. Not sure what I am doing wrong, please help.
It is a simple page with one multiline textbox that when i click submit a hidden DIV should pop up and say, Please wait while this processes...Don't click on anything.(they may submit 1000 items so it takes time.)
what's weird is i notice if i uncomment the Alert buttons, the alerts pop up and I actually do see the DIV, but if I take away the alert buttons, I am not seeing it.
here is my javascript.
function do_totals1()
{
// alert("Here-1");
document.getElementById('pleasewaitScreen').style.display = 'block';
// alert("Here-2!");
do_totals2();
window.setTimeout(function () {
"do_totals2()";
}, 4000);
//
// alert("Here-3!");
// window.setTimeout("do_totals2()", 1);
}
function do_totals2()
{
alert("Here-4!");
wait(4000);
document.getElementById('pleasewaitScreen').style.display = 'none';
}
<div id="pleasewaitScreen" style="display:none;position:absolute;z-index:5;top:50%;left:5%;">
<table bgcolor="#000000" border="1" style="border-color:blue; height:300;width:400" cellpadding="0" cellspacing="0">
<tr>
<td style="width:100%;height:100%" bgcolor="#CCCCCC" align="center" valign="middle">
<br /><br />
<font face="Helvetica,Verdana,Arial" size="5" color="#000066"><b>Processing... Don't click on anything until ESN(s) populate the grid below.</b></font>
<br /><br />
</td>
</tr>
</table>
</div>
This is probably what you're asking for:
function do_totals1() {
document.getElementById('pleasewaitScreen').style.display = 'block';
// we don't want to call do_totals2 directly, because it is what hides the element.
window.setTimeout(do_totals2, 4000); // setTimeout accepts a function reference
}
function do_totals2() {
// if wait is effectively a thread sleep function, you don't want to use it.
// if javascript doesn't release control of the thread (there's only one for your browser tab),
//the UI will never be updated, and you won't see that the element was shown.
document.getElementById('pleasewaitScreen').style.display = 'none';
}
If all you are doing is showing an element then hiding it 4 seconds later, you can do this instead:
function do_totalsN(){
var ele = document.getElementById('pleasewaitScreen');
ele.style.display = 'block';
setTimeout(function(){
ele.style.display = 'none';
}, 4000);
}
If you just want to show the "Please wait while this processes..." and then clear it after 4 seeconds, this'll do
function do_totals1()
{
document.getElementById('pleasewaitScreen').style.display = 'block';
setTimeout(function() {
document.getElementById('pleasewaitScreen').style.display = 'none';
}, 4000);
}
Well, basically you don't call it that way you either do this:
window.setTimeout("do_totals2();",4000);
or
window.setTimeout(function(){
do_totals2();
},4000);
So basically, remove the quotes and you will be fine
Here is more info
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.