Frameset Demonstration

This note shows the use of JavaScript and CGI to
  1. Prevent a page being framed by another site
  2. Reload a page in its correct frameset
  3. Generate a bookmarkable URL for a particular frame combination

Regular Frameset - can be reframed, title stays the same regardless of body content, etc.

Protected Frameset - framing is restricted, title may be updated to reflect contents.

the JavaScript

The following script in the document head will reload the parent document if it is incorrect. The Alert is optional, and a simple match may be used instead of a substring if the CGI script is not required. top may be used instead of parent to force the frameset to the whole page.
<script language=JavaScript>
  var ploc = parent.document.location + '' ;
  // parent URL must contain this substring
  if (ploc.indexOf('domain/path/frameset.html',0) <0) {
    alert('Wrong Frameset '+ploc) ;
    parent.document.location='/cgi-bin/frameset/domain/path/frameset.html?f1=f1.html&f2=f2.html&title=New+Title'
  }
</script>

the CGI

this script replaces named frames in a template with values coded in the URL, calculates content length and modification time, processes If-Modified-Since requests, adds a BASE tag, and serves the frameset.

Each possible set of frames within the frameset has (the possibility of) a unique URL, which may be bookmarked. Each individual frame page can have a link to the correct parent frameset.

Frame names (and the reserved name title) are coded in the URL using the HTML FORM METHOD=GET convention. If slash "/" characters are required, some changes may be necessary.

If you want to set the frameset title, and hence be able to bookmark the frameset, you must use the CGI script in the menu, which causes the frameset and all frames to be reloaded (though they should be cacheable and capable of returning status 304 - not modified). Otherwise you can just use the CGI from the JavaScript function, to reload the correct page in the body frame. If there are few menu items, it may be practical to have separate files for each frameset-body combination, and not bother with the CGI script at all.

This page discusses some of the problems of robots indexing frameset documents.

Andrew Daviel, Vancouver Webpages