Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove header frame from dynamic frameset?

Status
Not open for further replies.

Roastbeef

IS-IT--Management
Mar 22, 2001
11
US
Hello all - I would like to add the following dynamic frameset functionality to a Website I'm working on:


How can I add a link to the top header frame that allows the user to remove the top header frame and view the page in the bottom main frame in the current browser window? Note the URL of the page in the bottom frame varies. Thanks!
 
Here ya go:
Code:
<a href=&quot;javascript:document.location=bottom.document.location&quot; target=&quot;_top&quot;>close top frame</a>
That's assuming your bottom frame is called &quot;bottom&quot;.

Note that the target=&quot;_top&quot; does NOT mean the top frame, it means the top LEVEL frame, in other words, the whole browser window.

The href sets the current document to the document of the bottom frame, and sets the target to the top level frame, which effectively removes all other frames.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I'm aware of this option assuming the bottom frame is within the frameset's site. The problem is the bottom frame will be linking to site's OUTSIDE of the frameset's site. Any other options?
 
I was not aware of this, but the &quot;Same Origin&quot; security policy forbids being able to do this. I found info on this policy on the Netscape site at: under &quot;Client-Side Javascript Reference, Javascript Security, Same Origin Policy&quot;.

If you do find a way around it, it's probably a security hole. Even the framset document cannot access the url of the document in the bottom frame, even though it was the one that specified that url in the first place! Stupid, huh?

I don't think there is any way to do what you want.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Bummer. Thanks anyway tsdragon. I thought there might have been some way to do this since the bottom frame's URL is part of the frameset's URL (using a dynamic frameset). Is there any way to set a cookie or some other variable that saves this URL which then can be accessed and used to open the bottom frame's external URL? Any ideas? Thanks!
 
Apparently, because of the security cited above, unless you can add some code to the page(s) which will be loaded in the bottom frame, there is nothing you can do to access the url in the bottom frame. Note that if the URL is always going to be the same one you loaded via the frameset, you could store that url in a variable within the frameset and you should be able to get to it that way. But once the url in the bottom frame changes, there appears to be no way to get it. Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hmm. Is it me or does it seem like about.com uses Javascript for this? Check out:


There doesn't seem to be any CGI behind this. Try replacing the URL after the 'offsite.htm?' with any URL and the 'Turn off this top frame' in the top left corner updates.

The format (code and URL with ?) looks very similar to the 'dynamic framset' found at
Just can't figure out by looking at the code how they enable that 'Turn off this top frame' link to update dynamically. Any other thoughts?

Thanks!
 
The link DOES change, but if you go to a different URL in the bottom frame (by clicking a link to another site) the URL in &quot;turn off this top frame&quot; DOES NOT change to keep up, it still reflects the original URL you entered. I could easily figure out a way to do that, but that doesn't seem to be what you want. Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
tsdragon - That would be fine for now. I notice what you mean with about.com's approach. But mirroring how they do it would be fine for now. Let me know if you come up with anything. Thanks so much!
 
Here's one way to do it:

frameset.html:
Code:
<html>
<head>
<title>Demo</title>
<script language=&quot;JavaScript&quot;>
var theURL = self.location.search.substr(1);
if ( theURL == &quot;&quot; ) {
	theURL = &quot;bottom.html&quot;;
}
function HideTop () {
	self.location.href = theURL;
}
function setURL() {
	bottomframe.location.href = theURL;
}
</script>
</head>
<frameset rows=&quot;30%,70%&quot; onload=&quot;setURL()&quot;>
   <frame src=&quot;top.html&quot; name=&quot;topframe&quot;>
   <frame src=&quot;bottom.html&quot; name=&quot;bottomframe&quot;>
</frameset>
</html>

top.html:
Code:
<html>
<head>
<title> new document </title>
</head>
<body>
<h1>top frame</h1>
<a href=&quot;javascript:parent.HideTop()&quot;>close top frame</a>
</body>
</html>

bottom.html:
Code:
<html>
<head>
<title> new document </title>
</head>
<body>
<h1>this is the bottom frame</h1>
</body>
</html>

Load frameset.html using

www.yoursite.com/frameset.html?
The trick for loading the URL after the ? is in the script code in frameset.html, and in the onLoad call in the framset tag. You have to take the substr(1) of the search string to get rid of the question mark. Replace bottom.html in the script code and the bottomframe tag with the url of your default page for the bottom frame.

The trick for closing the top frame is in the link in top.html which calls the HideTop function in frameset.html.

bottom.html has nothing special in it at all.

Does that do what you want? You can try it out at:

and
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
tsdragon - This is perfect! This is exactly what I need. One final question. What would be the proper syntax to create a link within < noframes > tags to send those with frames disabled to the desired link (i.e. the one after the '?')?

Thanks again!!
 
Try adding this to the frameset:
Code:
<noframes>
   <script language=&quot;JavaScript&quot;>
      this.location.href = theURL;
   </script>
</noframes>
I'm not sure how effective this would be, since a browser that can't handle frames probably can't handle the javascript either. I don't have a browser that doesn't do frames, so I can't test it properly, but when I change all the frameset, frame and noframe tags to something unrecognizable it does load the page.

I've posted the change to the above URL, so if you have a non-frames browser you can give it a try. I'm not sure what to do with browsers that don't do javascript, since that's the only way I know of to get the query string with the desired url.

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You're very welcome. Glad I could be of some help. The best part is that I learned something from this exercise too.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top