Keep Your Page Framed |
|
Join the DiscussionIf your web site uses frames to "wrap" some static sections around the content area of each of your web pages then providing people with links to pages within your site will "break" your site in that the internal page will then be loaded without its frames wrapper. If there are only a handful of pages on your site then you can solve this by creating a frameset wrapper for each individual page that will load that page into a frameset surrounded by the other frames that your site uses. If your site contains dozens or perhaps even thousands of pages then doing this becomes impractical. Fortunately there is a way that we can alter the definition of our original frameset page (index.html) so that we can use Javascript to force the individual pages to reload themselves into the frameset. The first step is to define our frameset page. This is what it should look like (I have included both a <noscript> section to load the frameset that displays the home page if the browser doesn't support Javascript as well as a <noframes> section to display a message that frames are required if the browser doesn't support frames): Note that this is the one and only situation where you would ever code a Javascript outside of the head or body section of the page since in this instance we are using the Javascript to generate the frameset definition. The Javascript code expects that if there is a query string passed to the page that it is the address of the page that is to be loaded into the "main" area of the frameset in place of content.htm (which contains the content for your home page). You can of course change the arrangement of the frames within the frameset to suit your requirements as long as you make sure that the entries for the frameset in both the script and noscript portions of the page match except for the substitution of the curl variable. Once you have made the necessary changes to the frameset definition you then need to save it as index.html. The only other change that you need to make in order to keep your pages framed is to add the following Javascript code into the head section of every page on your site:
if (self.location == top.location)
top.location.href = 'index.html?' + escape(self.location); If a page containing this code is accessed from outside of the frameset then provided that the browser supports Javascript this code will cause the frameset to be loaded in its place and the current page address will be passed to the frameset to be loaded into the "main" frame within the frameset. If the browser doesn't support Javascript then the individual page will still display without its frameset. There is nothing we can do about that. The noscript section of the frameset page ensures that the home page still displays correctly if Javascript is not available and the noframes sections handle the situation where the browser doesn't support frames. |

