Forum Moderators: open
I just kinda stumbled upon this answer while writing some Java code, working on a way to force frames if necessary and in addition allow the back button to work to navigate back - one person I have seen said it couldn't be done. Thank goodness I got it to work, and my job will go on because of it.
Let me try to show you how it's done.
FIrst, put this script in your page with the frameset actually in it, in the <HEAD> area.
<SCRIPT LANGUAGE="JavaScript">
<!--
var ar0 = "top.htm";
var ar1 = "side.htm";
var ar2 = "main.html";
var str = location.search;
var pos = str.indexOf("&");
if (pos != -1) {
var num = str.substring(pos + 1, str.length);
window["ar" + num] = str.substring(1, pos);
}
// -->
</SCRIPT>
And just substitute those page names, which are generic, or add some if you wish, but keep them in order how you list them, it's important. THEN, put this in your page that's orphaned if you didn't force the frames (once again, in the <HEAD>) -
<SCRIPT LANGUAGE="JavaScript">
<!--
if (top.location.href.indexOf("index.html") == -1
top.location.replace("index.html?orphan.html&2");
// -->
</SCRIPT>
This will not only force the frames if it's not navigated to correctly, but the "replace()" command will remove the file from history so when you hit the back button, you are not trapped on that one page. The "&2" at the end is to be replaced with whatever number is the frame target of the page. If you need more info, feel free to email me - <see profile>
Hope you guys find this helpful
[edited by: tedster at 5:08 am (utc) on July 3, 2002]
One thing I needed was a way to use virtual includes to make this all easier - I'll include a little change you can put in your page to make it global.
For your orphaned page, change the script to look like this:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (top.location.href.indexOf("index.html") == -1
{
var index = new String("index.html?");
top.location.replace(index += location.href += "&2");
}
// -->
</SCRIPT>
I added a new variable called index that will have the location.href of the page appended onto it, so you can make it global, instead of having to manually enter every single page name.
ALSO...
One thing I forgot to mention is that on your index.html or whatever has the frameset in it, you need to make sure you're using document.write() because you have to make the <FRAME SRC="', ar0, '"> and so on in order for the Java to understand what it's referencing earlier in the page. If you want to look at a fully functioning page that incorporates this so my rambling makes more sense, just send me a message and I will show you how it works in the HTML code itself.
Have Fun!
MoBaAr