Register  |  Login

Question Details    

   Question

Time: 08:42 - Jan 02, 2008     Asked by: alanshortis      Status: Answered      Points: 125   

Force a window into a frameset using JavaScript - sub-folders problem.

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!

Ask a New Question

Become a Quomon Expert

Current Categories

 

Other Questions Needing Answers


   

Answer Discussion
Answer Discussion
Answer Summaries
Answer Summary
 
OK, I have solved it myself.

I simply replaced the script in the head of every document that I wanted to force into frames with:

<script language="javascript">

if(self.location==top.location)self.location="index.html?contact.html&
3";

</script>

This works with subfolders as you would expect by using:

<script language="javascript">

if(self.location==top.location)self.location="../index.html?sub/contact.ht
ml&3";

</script>

Expert:

alanshortis

Date:

Jan 03, 2008

Time:

02:32

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Question Answered

This question has been answered, and points have been rewarded to the following experts:

alanshortis: 125

You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.

 
No summaries have been submitted yet. Want to be the first?



Respond to this question:

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

 

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

   

"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it


All Questions


Language Options

English:

www.quomon.com

Español:

www.quomon.es

Quomon Blog

blog.quomon.com

Sponsors

Questions and Answers Software
Real Estate Postcards
Marketing Fulfillment