Hello.
I am using a JavaScript to force a window into a frameset if a user has namaged to open a page that shuld not be viewed alone.
The difficulty was that I wanted the page they were attempting to view to appear in the bottom frame of the frameset. I found a script that works, but am having some trouble when the page they want to see is in a subfolder.
Here is the code for index.html - the frameset:
<html>
<head>
<title>TRACK development</title>
<link rel=StyleSheet href="style.css" type="text/css" />
<script language="JavaScript">
var ar0 = "top.html";
var ar1 = "menu.html";
var ar2 = "search.html";
var ar3 = "contact.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>
</head>
<script language="JavaScript">
document.write(
'<frameset rows="55,20,25,*" border="0" frameborder="0" framespacing="0">',
'<frame src="', ar0, '" name="top" border="0" marginwidth="0" marginheight="0" noresize scrolling="no">',
'<frame src="', ar1, '" name="menu" border="0" marginwidth="0" marginheight="0" noresize scrolling="no">',
'<frame src="', ar2, '" name="menu" border="0" marginwidth="0" marginheight="0" noresize scrolling="no">',
'<frame src="', ar3, '" name="content" border="0" marginwidth="0" marginheight="0" noresize>',
'</frameset>'
);
</script>
</html>
And in the head of every page that should not be seen outside of the frameset I have:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (top.location.href.indexOf("index.html") == -1)
top.location.href = "index.html?page.html&3";
// -->
</SCRIPT>
Anyone openeing 'page.html' will be sent to the frameset, but in the tom frame they will see 'page.html', not 'contact.html' as defined in the frameset.
Now, the problem.
This works 100% if all pages are in the same folder, BUT not f the page I want to force into the frames is in a sub folder. I used the following code in the page in the sub folder:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (top.location.href.indexOf("../index.html") == -1)
top.location.href = "../index.html?subfolder/page.html&3";
// -->
</SCRIPT>
Now, I can see noe reason why this wouldn't work, but it fails. The browser appeasrs to try and send you between 2 pages and just freaks out!
I tried pointing it to a different file in the subfolder so rather than 'page.html' specified 'page1.html' and that works fine as long as the script is not in 'page1.html'. It only fails if the page you point to has the script in the top line.
This is driving me nuts. I can't see why it would do this. A 'quick fix' would be just to keep everything in the one folder... But wiwht more than 200 pages in subfolders (so far) updating all of my links would be a mammoth task.
Any help would be fantastic!