Forum Moderators: open

Message Too Old, No Replies

Removing the other frame

Removing the other of two frames

         

hunkymonkey

10:51 pm on Sep 23, 2004 (gmt 0)

10+ Year Member



I have a page which is made up of two frames, say, "top" and "bottom". I want to make it so that when any link in the top frame is clicked, the bottom frame closes, and the browser displays the chosen link on the whole page.

I figure I can use something like
<body onunload="removeBottomFrame()">
to catch the event, but how do I close the other frame and still allow the link to be followed?

StupidScript

11:15 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome, hunkymonkey!

No script involved:

<a href="whatever.html" target="_top">Link</a>

Adding this target attribute puts the requested document in the "top" frame ... which is the browser window itself.

hunkymonkey

11:28 pm on Sep 23, 2004 (gmt 0)

10+ Year Member



That's a great idea, but it won't work for me. This is all part of a dynamic system where I don't know what links will be in the top frame. If I did, I could put that target=_top on every one of them, but I can't. Some location changes even come from Java applets.

I've tried things like putting this in my frametop.html:
<script language="javascript">
function loseFrame() {
top.location.href=document.location.href;
}
</script>
<body onunload="loseFrame();"/>

But it changes top's location to the then-current location of the top document, and the link you just clicked on is lost forever. (Worse yet, you end up in this recursive loop--onunload keeps getting called for every link, keeping you on that page forever.)

Can it be done? Can I capture the new href somehow? Can I remove the frame without changing the "location" attribute, allowing the browser to continue on with what it was doing with it?

If it helps, I'm on a system that's guaranteed to be IE only.

Rambo Tribble

1:52 am on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could put an onclick event handler on your links that adds the target="_top" attribute to the clicked link before returning "true", allowing the link to then proceed. Do this by calling a function at window or body onload to loop through the document.links[] array adding the event handler to each.

hunkymonkey

3:50 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



That's a cool idea. It would almost work. However, like I mentioned, some of the links are going to be from Java applets, and I can't change those.

StupidScript

6:58 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you loading docs from other people's domains into your top frame? If so, you will have no options, as various security thingys will keep you from gleaning the href info you would need.

Are you generating your own pages with dynamic links provided by some process? If so, you would have control of the <body>, at least.

This comes from trying to figure out why you have no control over the code in the top frame. Your only option may be to provide a "Remove Frames" link on the doc you control.

hunkymonkey

7:40 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



I appreciate the comments. I guess I'll have to break down and tell you what's going on. I'm developing stuff in Livelink. It's an off-the-shelf document management system, and it provides a lot of the things a typical person would want to include in their pages--a common header, for instance. The header is a built-in Livelink chunk of code that can be called from a pre-processed html document. I probably shouldn't say this, since my job kind of depends on Livelink for work to do, but Livelink's about the worst-coded hunk of convoluted garbage I've ever seen.

That said, I did figure out the solution I was looking for. And I guess I have to be thankful to Livelink for this one. The common header code allows you to pass in the name of a javascript function that does something with any url that's picked from the header. So all I have to do is create my javascript function that accepts a url, and set the top-level window's location to that url. Done. The solution was easy. Finding a solution like that in Livelink is extremely painful.

But it's done. If you still want to help, you can look at my other post about windows disappearing.

Thanks.

Rambo Tribble

1:29 pm on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Once the links are part of the HTML, it should make no difference where they came from in terms of the event handler approach working