You are here: irt.org | FAQ | JavaScript | Frame | Q103 [ previous next ]
I get asked variations on this question quite often, and normally I reply sorry "no can do". However where someone actually describes the effect they are trying to achieve it is sometimes possible to suggest a workaround.
The reason why this is normally not possible, is that where a frame contains a document from another server the browser restricts what information you can retrieve from that frame, i.e. the top frame cannot find out the location of the bottom frame.
However, if you are likely to know the location of the bottom frame as you may have place the content there yourself, then it may be possible.
If however the user navigates on from the url in the bottom frame to other urls, then you'll only know what was originally in the bottom frame - not whats in there now. If the user presses the "kill Frames" option then the solution below will load the last *known* contents of the botFrame in the top frame.
If thats okay then the following will help you out. If not then: no can do.
1. define a variable in the topFrame called lastKnownURL, that will initially have the URL of the content loaded into the bottom frame.
2. When a user selects a URL, store this URL in the variable lastKnownURL, e.g.:
<SCRIPT LANGUAGE="JavaScript"><!-- var lastKnownURL = 'bottom.html'; function lastknown(href) { lastKnownURL = href; parent.otherFrameName.location.href = href; } //--></SCRIPT> <A HREF="javascript:lastknown('http://www.somewhere.com/')">go somewhere</A>
3. Include a button to kill the frame, e.g.:
<FORM> <INPUT TYPE="BUTTON" VALUE="Kill Frames" onClick="parent.location.href = lastKnownURL"> </FORM>