1. Computing & Technology

Discuss in my forum

Building an Automatic Frame

Writing the CGI

By , About.com Guide

Now, you can create a frame for each link that you have on your site, but that would be a lot of work, and while you have the templates if you read page 1, it would still be a bear to maintain. It is much better to write a simple CGI to build the frames for you automatically.

I wrote this CGI in Perl, but if you are more comfortable with another language, it can easily be adapted.

The first thing the CGI will look for is a parameter listing the URL to be framed. That is what you would pass the CGI. Using that and the referring Web page, we can build the frameset.

Sample Code

Here is the meat of my CGI:

 # if there is no parameter, re-open the last page.
 if (!$q-<param())
 {
 my $url = $q-<referer() ? 
 $q-<referer() : 
 "http://webdesign.about.com/";
 print $q-<redirect("$url");
 } elsif ($q-<param("top")) {
 &buildtop;
 } else {
 &buildframe;
 } 

The two sub routines simply build the HTML for the two different pages, that we wrote on page 1. The source is available here.

Adding a Link

When you add a link to an external site, you first point to it with your CGI. Make sure that you have the full URL, including the "http://" and the link will load in a frameset:

<a href="/cgi-bin/ frameit.cgi?url=http://webdesign.about.com/"> See it in Action</a> 

Note: everything in quotes in the above URL should be listed all on one line with no spaces

See it in Action

©2012 About.com. All rights reserved.

A part of The New York Times Company.