CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
is there any way to clear the HTML output printed by CGI perl


New User

Jul 23, 2010, 11:39 AM

Post #1 of 2 (3879 views)
is there any way to clear the HTML output printed by CGI perl Can't Post


I wrote a code in to download the data from a database using perl CGI. My prob is when the download is taking place i need to display the page with the message (for ex:"2/30 downloading") is there any way to dynamically clear the html page using perl CGI


Jul 23, 2010, 1:22 PM

Post #2 of 2 (3876 views)
Re: [brsaran] is there any way to clear the HTML output printed by CGI perl [In reply to] Can't Post


When you refer to "download", I nearly assume that you are physically downloading a file through your browser download dialog. If I am right in saying, you are "reading" data from a database, and whilst the process takes place you would like to dynamically output its progress.

Using CGI alone, this wouldn't be possible (theres no way to clear the screen, without "re-opening" the page). However, although i've never tried, your task would be possible with a client-side language (javascript).

Non-dynamically, you would print output like the following:

#i.e. in a loop 
print "$message\n";

for ex: "1/30 downloading"
for ex: "2/30 downloading"
for ex: "3/30 downloading"

Dynamically, you would print a block of javascript with code inside that calls a function elsewhere, passing perl variable:

#i.e. in a loop 
print "<script type=\"text/javascript\">progress('$message');</script>\n";

#Outputs (last loop iteration):
for ex: "30/30 downloading"

Although it may look as if its only outputted 1 line, its actually outputted the javascript block multiple times, but is only visible in the source code.

Anyway, using this theory, I wrote a quick/basic example of how its done. I tested in Firefox 3.6.6 and Internet Explorer 8 only:

#! /usr/bin/perl 
use strict;
use CGI ':standard';
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
print "Content-type: text/html\n\n";
print qq(
<title>CGI Dynamic Progress</title>
<script type="text/javascript">
function Progress(message) {
var e;
if (document.getElementById) { e = document.getElementById("progressdiv"); }
else if (document.all) { e = document.all["progressdiv"]; }
else if (document.layers) { e = document.layers["progressdiv"]; }
e.innerHTML = message;
<div id="progressdiv"></div>
for (1 .. 1000) {
my $message = ($_ < 1000) ? "Loop iteration: $_" : "Finished";
print "<script type=\"text/javascript\">Progress('$message');</script>\n";
print qq(

Hope this helps,


Edit: I found a very similar script. I have edited the javascript to ensure its more browser compliant.

(This post was edited by Zhris on Jul 23, 2010, 4:11 PM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives