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

Q1211 How do I bookmark a frame using Javascript?

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

Only in Internet Explorer 4+:

<script language="JavaScript"><!--
function addtofav(linkUrl,linkTitle){
   if (!document.all) {
      alert('Please hit ctrl-d to bookmark this page');
   }
   else external.AddFavorite(linkUrl,linkTitle);
   return false;
}
//--></script>

<a href="javascript:;" onClick="addtofav(window.location.href,document.title); return false">Add this page to favorites</a>

Hal Pawluk writes:

I use a technique for bookmarking framed pages that you might be interested in. Essentially, I open the framed page in a popup window, then bookmark that, then close it.

Here's how I describe it on my site:

------------------------------

Bookmarking Framed Pages:

Just using the menu or ctl/cmd-D to bookmark a framed page won't work. All that's bookmarked is the outer frameset page, so when users come back to your site, they have to dig through it again to find the information they want. When I put my E-Notes into frames, I decided to do something about it.

Start by putting this script into the head of your page (link to a Dreaweaver extension available below):

<SCRIPT>
function frameBooker_hp(){
var is_4up = parseInt(navigator.appVersion);
var is_mac = navigator.userAgent.toLowerCase().indexOf("mac")!=-1;
var is_ie = navigator.userAgent.toLowerCase().indexOf("msie")!=-1;
var thePage = location.href;
if (thePage.lastIndexOf('#')!=-1) //if there, strip anchor
thePage = thePage.substring(0,thePage.lastIndexOf('#'));
if (is_ie && is_4up && !is_mac)
window.external.AddFavorite(thePage,document.title);
else if (is_ie || document.images)
booker_hp = window.open(thePage,'booker_','menubar,width=325,height=100,left=140,top=60');
booker_hp.focus();
}
</SCRIPT>

That will open the framed page in a small new window where it can be bookmarked. Now select an image or text with a null link in the body of the page and add the call to the frameBooker_hp function like this:

<A href="javascript:void(0)" onClick="frameBooker_hp()">Bookmark this page</A>
<A href="javascript:void(0)"><IMG src="imagename.gif" onclick="frameBooker_hp()"></A>

This will work but you see only a portion of the page being framed and the user may be confused because there are no instructions on what to do next. To solve that problem, insert the following code immediately after the tag in your page. It will push your content out of sight and tell the user what to do to bookmark the page:

<SCRIPT language="JavaScript" name="frameBooker_hp">
if (window.name=='booker_') {
  var pre_fix = document.images? '<BR>':'';
  document.write(pre_fix + '<P align="center">'
  + 'Please use Ctrl/Cmd-D or the menu now <BR>to bookmark the framed page<BR>'
  + 'then <A href="javascript:window.close();">close this window</A></p>');
}
</SCRIPT>

If you're a Dreamweaver user, you can save yourself some effort by downloading my frameBooker extension from the Dreamweaver page (mouse over 'Other Stuff' and click on 'FrameBooker'). I've tested it with Netscape 3+ and Explorer 4+ on Windows and the Mac.

Feedback on 'Q1211 How do I bookmark a frame using Javascript?'

©2018 Martin Webb