Redirecting with Javascript

We don't recommend Javascript for beginners, but with a simple block of code we can solve some problems that come up when using frames.

When building a site with frames you have two different kinds of pages. You have frameset pages and you have source pages. Source pages are those that are assigned to a frame window with the src="pagename" attribute, and display in the main window. (See Frameset Code)

The proper way to build a frames site is to build a separate frameset page for each source page. We get our pages crawled by placing the body content of our source page and all site links in the noframes section of each frameset page. (See Frameset Code - bottom of frameset)

Once our pages get indexed, what if a source page comes up in a search result and someone clicks on it? Normally they would just see a static page without frames. How do we get that static source page to come up in its designated frameset?

We perform this task by placing a simple block of Javascript below the headsection of our source page:
The script:

</head>
<SCRIPT TYPE="text/javascript">
<!--
if (parent.location.href == self.location.href) {
if (window.location.href.replace)
window.location.replace('frames_template5.html');
else
// causes problems with back button, but works
window.location.href = 'frames_template5.html';
}
// -->
</SCRIPT>

Now when someone directly accesses the source page it will redirect to the frameset page created for it.

For more information on using this technique see Frames and Search Engines in our HTML 4.0 Online Tutorial.

This mini tutorial was developed using our Free Frames Template Kit . 5 linked and fully operational pages included with backgrounds and images for your use. Redirection code installed. Please visit Create a Site and download the Kit.

Net Success 2000 Plus Inc
Po Box 1508
Somerset KY 42502
Copyright 2008
Last Modified: July 28, 2008
Create a Website Home
Restore Frames