Bookmarks: Add Favorite

This page is obsolete and retained for archival purposes only.
Updated page with a Firefox/IE code example is available here:
Bookmarking a page in JavaScript: external.AddFavorite and sidebar.addPanel

Question: How do I invoke the browser's Add Favorite dialog?

Answer: In Internet Explorer 4.0 and newer versions, you can invoke the browser's Add Favorite dialog by calling the method window.external.AddFavorite:
   window.external.AddFavorite('URL','bookmark text').
Other browsers do not have AddFavorite method (and might not have the Add Favorite dialog at all). But your script can just remind the users to create a bookmark by using the Bookmark menu item or keyboard shortcut (see example below).

Example: In Internet Explorer, this script creates a hyperlink that displays the Add Favorite dialog. In other browsers, the script reminds the user to create a bookmark by clicking Bookmarks | Add bookmark or press Ctrl+D.

Here's the source code of this example:
if (navigator.appName.indexOf("Microsoft")==-1) {
 document.write (
   'To bookmark this site, click '
  +'<b>Bookmarks | Add bookmark</b> '
  +'or press <b>Ctrl+D</b>.'
 )
}
else if (parseInt(navigator.appVersion)>3) {
 document.write (''
 +'<a '
 +' onMouseOver="self.status=\'Bookmark this site\'" '
 +' onMouseOut="self.status=\'\'" '
 +' href="javascript:window.external.AddFavorite'
 +'(\'http://www.JavaScripter.net/faq/\','
 +'\'JavaScripter.net FAQ\')">'
 +'Click here to bookmark this site</a>.'
 )
}

See also other JavaScript dialogs:

  • Alert (message box) dialog
  • Confirm dialog
  • Prompt dialog
  • Print dialog
  • Find dialog
  • Copyright © 1999-2011, JavaScripter.net.