Last Updated:

Loading menus for a site with frames

Frames in HTML allow authors to present documents in multiple sections, which can be independent or nested windows. For example, one window may have a menu to manage the site, and another may have separate pages that you can navigate between using the menu. To set frames, you need at least three HTML documents: the first two are documents loaded into different frames, and the third is a document that says that the browser window must be divided into 2 frames and loaded into these frames 2 HTML documents. So, what should this document contain? Here's the simplest HTML document:

<FRAMESET frameBorder=0 frameSpacing=0 cols=200,*>
<FRAME name="menu" src="1.htm" scrolling=no>
<FRAME name="site" src="2.htm" noresize>

As you can see from the example, this document should not have a <body> tag. The frames themselves are specified by the <FRAMESET> </FRAMESET> tags, and there can be multiple <FRAMESET> tags in a single HTML document. In our case, the <frameset tag> specifies that you want to create two vertical frames, with the first one having a width of 200 pixels and the second with everything that is left (cols=200,*), the width of the frames can also be set in fractions and percentages, for example, cols="20%,80%" means that 2 vertical frames with a width of 20 and 80 percent of the width of the screen will be created, you can also create horizontal frames if you specify rows instead of cols. The frameBorder parameter specifies the width of the border between frames, the frameSpacing parameter specifies the width of the empty space between them. Using <FRAME> tags, you can specify the name of the files to be loaded (srс parameter), the scrolling parameter is responsible for the appearance of scroll bars if the dimensions of the HTML document exceed the dimensions of the frame, in our case, the scroll bars of the first frame are absent.

Now that we've learned how to load different HTML documents into frames, we can manage the contents of one frame from another. Such a task can arise if necessary to make a site management menu. To load a document into another frame when you click a link in one frame, you must make the target parameter in the <a> tag equal to the name of the frame into which you want to load the HTML document. In our case, if we make a link in the menu frame: <a target="site" href=doc.htm>doc<a>, then when you click on this link, the doc.htm document will be loaded into the site frame.

Many Webmasters have a very bad attitude towards frames. I've linked to the frames so that the site menu doesn't reload when you go to every page. However, there is another side to this coin: have you ever come across HTML documents that completely lack links to other pages? If you did, then I'm willing to bet that these documents should have been loaded into a frame, and all links should be located in the control panel of the site. But the user who goes to this page will not understand and will leave it, and your site will earn a bad reputation. How does the user even get to such pages? Here everything is simple - through a search engine.

But there are solutions to this problem.

Of course, here the means of the HTML language itself can not do, and you will have to at least use JavaScript, and even PERL (you can PHP or a CGI application written in anything).

1. The first thing to do is to check if there is a frame of the site control panel. If there is, then nothing needs to be done.

2. If there is no frame, you need to change the code of this page or upload a new one instead of this one.

You can check for frames in JavaScript:

<script language="JavaScript">
function prow ()
if (parent.frames.length==0)

This procedure is started when you start loading an HTML document, sometimes the user may not understand what is the matter (so quickly the transition to a new document is carried out). If the parameter "parent.frames.length" is set to 0, then the parent frame and therefore the frame with the menu are missing and another HTML document must be loaded. If the doc.htm procedure does not detect a menu frame when loading a document (if doc.htm contains this procedure), the URL of the current document will change to, that is, the doc_.htm will be loaded. In our case, the doc_.htm contains the following code:

<FRAMESET frameBorder=0 frameSpacing=0 cols=200,*>
<FRAME name="panel" src="menu.htm" scrolling=no>
<FRAME name="site" src="DOCUMENT_NAME.htm" noresize>

So everything works, but there is one drawback: for each HTML document there should be such a document that would contain information about loading the first in a separate frame.

It is easy to see a pattern here: all these additional HTML documents should be the same and similar to the above code, only differ in the DOCUMENTNAME parameter. This means that the output of such documents can be entrusted to the script, and the DOCUMENT_NAME can be reported as a parameter. The code of the new procedure will be the same, only different from the new URL, now the new document will not be loaded, but a request will be made to the CGI (PHP, etc.): document. URL="". In this case, the script will be launched, and document_NAME will be passed as a parameter. This script is written by someone who can do what (me, for example, on PERL). If you can't do anything, write in PERL:


#write to variable $str DOCUMENT_NAME

print "Content-Type: text/html\n\n";
print "<html><head></head><FRAMESET frameBorder=0 frameSpacing=0 cols=200,*>\n";
print "<FRAME name=menu src=".$c."".$c." noresize>\n";
print "<FRAME name=site src=".$c."".$str.$c." noresize>\n";
print "</FRAMESET></html>\n";

An example of how this script works, see the website: write down the path to the computer flea market in the browser line: and see what happens. The menu and the page of the computer flea market should load.

That's it, it works; all you have to do is replace the URLs in these examples with your own.