Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q783 How do you bookmark a frame within a frameset, but making sure that the bookmark returns the visitor to the frame within the frameset, and ensure that someone else cannot get my frameset to frame their page inside mine?

You are here: irt.org | FAQ | JavaScript | Bookmark | Q783 [ previous next ]

Say for example you have a frameset like this called top.html:

<frameset cols="50%,50%">
<frame src="frameA.html" name="nav">
<frame src="frameB.html" name="display">
</frameset>

Then it needs to be changed to this top.html:

<html>
<script language="JavaScript"><!--
document.write('<frameset cols="50%,50%">');
document.write('<frame src="frameA.html" name="nav">');
document.write('<frame src="http://www.somewhere.com/' + (location.search ? location.search.substring(1):"frameB") + '.html" name="display">');
document.write('<\/frameset>');
//--></script>
</html>

Change http://www.somewhere.com/ to match the name of your server [and optionally include a pathname].

Elly Lisen has suggested an improvement on the above script:

I think that reloading the whole thing on every link defeats the purpose of frames which are used to avoid extensive reloading... If you use the JS frame structure described above and insert a button in one of the frames that will invoke call the following function, it could partially solve the problem:
function bookmarkPage() { var address = eval("'" + top.location.href + "'"); i = address.indexOf("?"); if (i!=-1) address = address.slice(0, i); else address = address.concat('?'); for (i=0; i<1; i++) address = address.concat(eval("'" + top.frames[i].location.href + "'"),'&'); if (i==1) address = address.concat(eval("'" + top.frames[i].location.href + "'")); i=/\#\&/g; address = address.replace(i,'&'); if (document.all) window.external.AddFavorite(address, 'Our Bookmark'); else if (document.layers) { alert("You are using a browser incapable of adding a bookmark dynamically. " + "Wait until the document will be reloaded and go to BOOKMARK=>ADD A BOOKMARK " + "in the option bar of your browser. The correct address will be recorded " + "to your bookmark file automatically."); top.location.href = address; } }
It will automatically add a bookmark for the correct layout of frames within a frameset one level deep. I think it is possible to make it work for any depth of frames (frames within a frame), but I have not done it yet.

Note: as the above code stands it will generate errors in browsers prior to Netscape Navigator 4 and Microsoft Internet Explorer 4, as it makes use of Regular Expressions, and slice(), concat() and replace() which are not supported in all browsers.

©2018 Martin Webb