Using Redirects with Frames
This tutorial is for people who have sites that use frames. In a framed site, there is usually at least two frames; a navigation frame which holds the links to navigate around the site, and a content frame which holds the page’s content. Of course there may be more than two frames, but I’ll focus on just two for simplicity.
Normally, a user navigates to a site by entering the URL like http://scriptasylum.com. Usually, most people don’t usually type in the specific page they want, they use the site’s navigation. But let’s say for example, a user does type in the exact URL of the page they want to go to. This works OK…. until you get to a site that uses frames.
Since most people usually use one frame for navigation and one or more for site content, typing or bookmarking the URL directly causes a problem: The page loads, but the rest of the other frames aren’t loaded. Therefore, you can’t navigate around the site unless they happen to know the exact URLs of the pages they want to see.
Click the links below to demonstrate this effect.
The only link that loaded the frames the proper way was the “Index Page” link. That is because this page contains the HTML that sets up the frames. In order to load the site the proper way, the user must always go to the site using the index page.
This solution works great; it’s easy to add to any page and there’s nothing to change. The only bad feature is the site will always load the default home page no matter what URL they actually typed. Some people may find this annoying. It would be really great if the user could simply type the page they wanted to go to and it would automatically load the proper frames with the page they typed in where it should be!
The only page this would be ideal in would be the navigation page. If someone typed in the navigation page URL (which is unlikely), it’s OK for the frameset to load the default home page setup.
A Better Way
With a little more tweaking to the script above, you can redirect andload the page the user wants. The trick is to “tell” the index page what page the user really wanted to see. So, when the script redirects to the index page, a script will “read” this information and load the right page. Just use the script above, but add a question mark and the page URL to the end of the rest of the URL:
The example above would redirect to index.html and then load page1.html into the content area instead of whatever the default page would have been. You must put the name of the current page in the script though. So, in page2.html, you have to put “?page2.html”. Don’t forget: this has to be done to every page EXCEPT the navigation page and the index page.
You’ll have to add another little script to the index page too. This is so it can know which page to really load. If you dont have a ? in the URL, it will simply load the default home page. Just paste this script into the HEAD section of your index page (the page that sets up the frames):
The only setting you have to adjust is the frame name. When you set up your frames, you must have given at least the content frame a name. Just enter this name in the script above. This script also assumes the content frame is not nested inside any other frames. If so, you can adjust the script accordingly.
Click the links below to demonstrate the script in action. Each of these links loads justthe page each says.
Each link opened the page intended without having to re-navigate to the specific page once the frameset was loaded.
OK, now I will recap which script is to be in which page just to make sure no one gets confused.