User Tools

Site Tools


software:html

Frameset Referencing

FORCE MANY PAGES INTO frames

http://www.webmasterworld.com/forum91/567.htm <pre> With search engines now indexing framed pages, lots of traffic is being sent straight to pure content pages, orphaned from their parent frameset. Building a separate frameset for each possible content page is one solution, but it can be a maintenance nightmare. This script handles the problem.

THE MAIN IDEA You can add ANY page's name to the end of a URL [after a “?”] Then you only need ONE frameset page to catch an indefinite number of orphan pages and put them into their frameset. This method offer very easy maintenance, especially when there are lots and lots of possible orphans for one frameset.

THE CODE Call this javascript code from the HEAD section of each child page. The code creates a variable from the URL of the page, and then passes that variable in the new location's URL. This means a “master” frameset can load this exact page in the content section:

passpage = document.URL if (top.location == self.location) top.location.href=“master.html?” + passpage

Then create just one “master.html” page. It holds the JavaScript code to decipher whatever URL is passed after the “?” and it writes that page into the content frame:

<html> <head> <title>Master frameset</title> </head>

<script language=“JavaScript” type=“text/javascript”>

origURL = parent.document.URL contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)

document.write('<frameset cols=“20%,80%”><frame src=“leftnav.html” name=“nav”><frame src=\“' + contentURL + '\” name=“content”><\/frameset>')

</script> </html> </pre>

<pre> THE BACK BUTTON With the basic code above, if someone comes to your page from a search engine, the redirect will place two pages in the browser's history, and this means that the Back Button, clicked once, will throw them into a loop.

But if you use the replace() method instead of simply reassigning the url, the Back Button issue is addressed. Only one page is placed in the browser history instead of two.

passpage = document.URL if (top.location == self.location) top.location.href=“master.html?” + passpage

Becomes: passpage = document.URL if (top.location == self.location) location.replace(“master.html?” + passpage) </pre>

software/html.txt · Last modified: 2022/09/07 17:10 by superwizard