Partilhar via


Add my page to a visitor's Favorites list

Here's a tip that Jim Buyens * , a FrontPage MVP, contributed awhile ago that shows how to create a link that adds a Web page to a visitor's list of Favorites.

Switch to Code view and add this script where you want the hyperlink to appear:

 <script>
  if (navigator.appName.substring(0,9) == "Microsoft")
  {
    document.write("<a href='" +
      "javascript:window.external.addFavorite" +
      "(document.location, document.title)'>" +
      "Add to favorites.</a>")
  }
</script>

This script works unmodified in any page. The expression document.location gets the URL of the page that contains the script, and the expression document.title gets the page title. This is the title you enter in FrontPage on the General tab of the Page Properties dialog box.

Unfortunately, the window.external.addFavorite() method that makes all this possible works only in Internet Explorer. An if statement therefore tests the first nine characters of the browser's identification string for the presence of the word "Microsoft". This condition will be false for any browser other than Internet Explorer, and as a result, the link won't appear in those browsers.

* Jim Buyens is the author of ten computer books, including most recently Microsoft Office FrontPage 2003 Inside Out, from Microsoft Press, ISBN 0-7356-1510-1.

Comments

  • Anonymous
    July 14, 2004
    Hi, Brant,

    Often we get questions in the newsgroups that ask how to do something that someone has seen on a Web site. This is one of those questions. The fact that IE is the only browser to allow it shouldn't stop us from providing the information as long as we also provide the appropriate caveat.

    Jim provided code that shows the link ONLY if IE is the browser. If scripting is turned off in the browser, there is nothing that can be done, at least I'm not at this time aware of any way to determine whether scripting is not allowed. However, because the link is scripted, if scripting is turned off, it wouldn't show up, so there's no harm in including it.

    IMHO, just because scripting may be turned off doesn't mean that we stop showing people how to use scripting, and just because IE is the only browser to allow scripting Favorites doesn't mean that it's necessarily wrong. After working with computers and teaching computer applications for 15+ years, I've learned that there is often no right or wrong way to do something, just different ways.

    Hope this helps.
    Lisa
  • Anonymous
    February 21, 2006
    Very nice blog!
  • Anonymous
    March 12, 2006
    Very interesting and beautiful site. It is a lot of helpful information. Thanks!
  • Anonymous
    March 15, 2006
    The comment has been removed
  • Anonymous
    May 07, 2006
    Hi.
    Great Site, Really really interesting and useful.
    <a href = "http://www.all-tech-here.info/">www.all-tech-here.info</a>
  • Anonymous
    September 23, 2006
    <a href="http://www.opera.com/support/tutorials/opera/using/hotlist/#addpanels"
    >Firefox and Opera 7+ will popup a window to bookmark a page if the link (&lt;a&gt;) has a rel="sidebar" attribute set.</a>

    For an unobtrusive script that works in even more browsers, check out <a href="http://www.dynamicsitesolutions.com/javascript/add_bookmark/">The Ultimate Add Bookmark Script</a>