Running a CGI Script When Page Loads
From statistics gathering to silent webmaster notification to email subscription solicitation, there can be any of many reasons for triggering a CGI script to run when a web page loads.
To specify the URL of a CGI program in an IMG tag, in lieu of a real image file, the CGI program will need to return an image to the browser before it finishes running.
Before and after the image is returned to the browser, the CGI program can be updating a log file, setting a cookie, sending an email to the webmaster, and anything else it is supposed to do.
Below is a synopsis of each method.
“OnLoad” Attribute Activates CGI Script
Automatic Form Submission to a CGI Program
The implementation guidelines contain code to insert the current web page URL and the user’s time zone information into the form.
Image Tag Launches CGI Program
As mentioned above, an image tag can be used to launch a CGI program. Instead of an image file, the SRC of an IMG tag contains the URL of the program.
When the CGI program runs, it will, of course, returns an image to the browser before the program completes its tasks.
IFRAME Tag Will Auto-Launch CGI Script
An IFRAME may be used to automatically launch a CGI script.
Any method discussed above may be incorporated into the web page being loaded into the IFRAME.
Alternatively, the SRC of the IFRAME can contain the URL of a CGI program instead of the URL to a normal HTML web page.
The CGI program can do whatever duties it is programmed to do and, before quitting, return an actual HTML web page for the browser to put into the IFRAME.