Silverdisc

See Also

Google Case Study

The future looks bright for SilverDisc and the Google Adwords API program. Download PDF

contact us online, or call 01536 412269

Self Referencing Framesets

The self-referencing frameset is a technique designed to allow frames to be used for branding, navigation and content, and to overcome the problems of hyperlinking, reduced link popularity, bookmarking and determination of location that frames present to Webmasters and Web users.

The technique involves making a framed page responsible for writing out its own frameset - a frameset that includes itself - if it detects that it is about to be displayed out of context. The framed page uses JavaScript to achieve this. JavaScript and Frames are very closely bound - the assumption is made that if JavaScript is available, frames are also available. If JavaScript is not available, the page is still usable, with all branding and navigation, but not in a frameset. This means it can be accessed by a wide browser park, including search engine spiders. All of the following criteria are fulfilled:

To show the self-referencing frameset in action, let's return to our original example. We had a five page Web site:

Because we are now using a self-referencing frameset, we do not need a page just to define a frameset - the index page can now contain its body copy as well as the frameset, so we only need four pages:

So, there are two self-referencing framesets, index.htm and sales.htm. Let's examine the code that writes the self-referencing frameset. In fact, it is just one line:

<SCRIPT LANGUAGE="JavaScript" SRC="writefs.js"></SCRIPT>

This line is placed between the HEAD and BODY sections in the index.htm and sales.htm documents.

writefs.js is responsible for two things:

The need to write the frameset is detected as follows:

var str = location.search; var writeFrames = (str.indexOf("nowritefs")) && (top.window.length == 0);

This gives a hint of what is to come. The self-referencing frameset works by writing a frameset reference to itself and passing a parameter of "nowritefs". [This is done to avoid infinite loops caused by some versions of JavaScript using the cached parsed copy of the page - but that's another story].

So the self-referencing frameset document is accessed using two different URLs - one of which does not contain "nowritefs" in the parameters, and one that does. The version that does not contain "nowritefs" in the parameters writes the frameset, and the version that contains "nowritefs" in the parameters does not write the frameset.

We now know whether we need to write the frameset. If we don't need to write it, we're done. Let's look at what we do if we need to write it. Firstly, we need to work out the URL of the frame we are writing. This is the same URL as the current document, but with a "nowritefs" parameter added:

if (str == "")
{ var bodyFrame = window.location + "?nowritefs"; }
else
{ var bodyFrame = window.location + "&nowritefs"; }

Finally, we are ready to write the frameset. For our simple frameset this is straightforward, so let's just look at all the code together. Here is the full source of writefs.js:

var str = location.search;
var writeFrames = (str.indexOf("nowritefs")) && (top.window.length == 0);
if (writeFrames) {
if (str == "") { var bodyFrame = window.location + "?nowritefs"; }
else
{ var bodyFrame = window.location + "&nowritefs"; }
document.write('<FRAMESET FRAMEBORDER="1" ROWS="100, *">', '<FRAME SRC="branding.htm" NAME="brand">',
'<FRAMESET FRAMEBORDER="1" COLS="200, *">', '<FRAME SRC="nav.htm" NAME="nav">',
'<FRAME SRC="', bodyFrame, '" NAME="bodyframe">', '</FRAMESET>', '</FRAMESET>'); }

Having written out the frameset in JavaScript, let's now consider what happens to both non-JavaScript and JavaScript compliant browsers.

Non-JavaScript compliant browsers

For non-JavaScript compliant browsers (such as search engine spiders, or users behind corporate firewalls) the frameset will not be written, so only the <BODY> content of the self-referencing frameset will be seen. This is fine - but what about the branding and navigation contained in the frameset? No problem - simply repeat the branding and navigation in the <BODY> section, using <NOSCRIPT> tags (consider using SSI or ASP to achieve this site-wide). So if nav.htm (the navigation frame) looks like this:

<HTML>
<HEAD>
<TITLE>Navigation Frame</TITLE>
<BASE TARGET="bodyFrame">
</HEAD>
<BODY>
<A HREF="index.htm">Home Page</A><BR>
<A HREF="sales.htm">Sales Page</A><BR>
</BODY>
</HTML>

then put this code somewhere into the <BODY>s of the self-referencing framesets (index.htm and sales.htm):

<NOSCRIPT><A HREF="index.htm">Home Page</A> | <A HREF="sales.htm">Sales Page</A></NOSCRIPT>

You can do likewise with the branding:

<NOSCRIPT><IMG SRC="logo.gif" ALT="Branding logo"></NOSCRIPT>

JavaScript compliant browsers

JavaScript compliant-browsers will write the frameset. The extra branding and navigation information will not be displayed since it is within <NOSCRIPT> tags.

Once the frameset is written, a decision has to be made on targetting. Hyperlinks can be targeted to two possible locations:

No matter which targetting method you choose, add or modify the appropriate <BASE TARGET...> tag to both the navigation and body content frames.

Summary

If you have any questions, e-mail info@silverdisc.co.uk.

 

Page 1 - 2 - 3 of 3