John said:
Hello, I have a cgi script that takes ~20sec to run. I'd like to have
a page appear when the page was submitted that told the user that
their results page would load in ~20 secs ... Is there a way of doing
this using javascript?
--------------------------------------------------------
START CODE
--------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
$|++;
print qq{Content-Type: text/html; charset=iso-8859-1
<html>
<head>
<title>My cool web page</title>
<script type="text/javascript">
var counter = 0;
var txt = 'Please wait 10 seconds... '
function doCount() {
++ counter;
if (counter <= 10) {
document.getElementById('nr').innerHTML = txt + counter;
setTimeout('doCount()', 1000);
}
else {
document.getElementById('nr').innerHTML = '';
document.getElementById('nr').style.visibility = 'hidden';
document.getElementById('nr').style.display = 'none';
document.getElementById('cgi').style.visibility = 'visible';
}
}
</script>
</head>
<body>
<div id="nr"></div>
<script type="text/javascript">
doCount();
</script>
<div id="cgi" style="visibility:hidden;">
};
sleep 10;
print ' HTML output CGI script goes here';
print qq{
</div>
</body>
</html>
};
__END__
--------------------------------------------------------
END CODE
--------------------------------------------------------
I've put a demo here:
http://www.dotinternet.be/temp/demo.cgi
Please view the page's source during those 10 seconds, and keep an eye
on the browser's progress bar.
Hope this helps,