One major annoyance I have with web sites that use frames is that if you open a link explicitly, it will load the page outside of its original frameset. Search engines complicate this matter even further, as they link pages within such sites directly.
Any solution to this problem must be capable of two things:
Once we use one of the two methods above to detect whether our page is valid, we need to redirect the current page to one that uses frames.
Unless you want to have a separate HTML file with a defined frameset for every document on your web site, the need to define and load a frameset dynamically becomes very apparent.
If you don't have access to custom CGI/PHP etc. on your Web server or don't want your URLs to get mangled, then a client-side solution may be in order.
The upshot to this is that bookmarking an URL using this method bookmarks the actual page. Our next solution will always bookmark the homepage. It's a matter of preference really.
We use the same frame detection code as the CGI method, but in this case, we redirect the browser to an alternate page which will dynamically load our frameset. The method I'm using employs a browser cookie to save the current page's URL, and the new page will use this cookie as it defines the frameset. We only wind up adding 7-8 lines of code to each page within the web site for detection, and the bulk of the code (which retrieves and deletes the cookie) is kept within the redirection page.
(The document.referrer property, which specifies the URL of the calling document is not properly supported under JScript 1.0, always returning the URL of the current page)
Show me the code!
Add this code (customizing it to your needs if necessary) to every file on your web site, right after the <BODY> tag on each page.
index2.html essentially defines the same frameset as the main start page (index.html) for my web site, except that it loads the right (main) frame dynamically as defined by our cookie:
On a final note, there may be some cases in which you might want to hard-code the URL which you define in your cookie. For example, if I link the menu.html file of my web site directly, I wouldn't want it to reload the frameset with menu.html as the left frame, and menu.html as the right frame (since this would be stored in the newURL cookie). In cases like these, make sure to specify the right file you want to redirect to. For example:
document.cookie = "newURL=" + escape("main.html") + "; path=/;"
This solution should work without any problems from Netscape 2.0 and Internet Explorer 3.0. The only time you will run into problems are if browser cookies are disabled, in which case the page will just redirect to the default page (as specified by index2.html).
NOTE! - Wim Vogel has pointed out to me that this solution prevents a user from printing any reloaded pages using Netscape 4.x. A description and workaround to this problem is available on Ivan Peters' site.
Last updated on February 06, 2000