PDA

View Full Version : How to put a page back in its frameset?


techmatters
07-14-2002, 05:48 AM
A number of search engines (including Google) now happily index the content pages from within a frameset. This means that when a searcher clicks on a link from the search engine, they arrive at the content page devoid of its navigation and other important elements. Is there a clever javascript (or other) method of detecting if a page is missing its frame and then force it to display back within its frameset?

neil.c
07-14-2002, 11:43 AM
1. stick a redirect into the <head> of the content page (content.html) like this:

<script language=javascript>
<!--
window.location="frameset.html?content.html"
//-->
</script>

2. stick this into the <head> of the frameset page (frameset.html):

<script language=javascript>
<!--
window.mainframe.location = window.location.search.substr(1)
//-->
</script>

mainframe is the name of the frame where you want the content to appear.

this means that when anyone stumbles across content.html they will be sent to frameset.html and 'content.html' will be sent in the location.search (the bit in the address starting with a '?'. when frameset.html opens, the bit after the '?' ('content.html') is loaded into the mainframe.

ok?

joh6nn
07-14-2002, 01:49 PM
you're on the right track, neil, but you forgot a couple of details. what happens if you don't have any extra information appened to the url?

i'll copy and paste my script from the old forum here:

anything in bold, you have to change to fit your site.

this first part goes in the page, where you create your frames. ie, frames.htm
<SCRIPT>
function frame_saver()
{
if (self.location.search)
{
self.FRAMENAME.location = "http://www.DOMAIN.com" + self.location.search.slice(1);
}
}

self.onload = frame_saver;
</SCRIPT>

this second bit goes in any frames that don't change, like frames you use for navigation.

<SCRIPT>
if (self == top) {self.location = "http://www.DOMAIN.com/frames.htm"; }
</SCRIPT>


this last part goes in all of the pages that are in the main frame; the ones that you want to be able to bookmark.

<SCRIPT>
if (self == top)
{
var url = self.location.pathname;
self.location = "http://www.DOMAIN.com/frames.html?" + url;
}
</SCRIPT>

neil.c
07-14-2002, 09:04 PM
yeah that looks better.