Bookmarking a page:external.AddFavorite() and sidebar.addPanel()

JavaScript FAQ | JavaScript Dialogs FAQ  

Question: Can I bookmark a webpage programmatically from JavaScript?

Answer: In Internet Explorer 4.0 and newer versions, you can invoke the browser's Add Favorite dialog by calling the method

. In Firefox, similar functionality can be achieved using the method
. The actual appearance of the dialogs depends on the browser, OS, and display settings. The screenshots below show these dialogs under Windows XP (Windows Classic theme):

Other major browsers do not support these methods. Still, your script can simply 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 displays the Add Favorite dialog. In Firefox, it displays the New Bookmark dialog. In other browsers, the script reminds the user to create a bookmark by pressing Ctrl+D.
Try this now: click the button Bookmark JavaScript FAQ!

This example uses the function
; here is the source code:
function createBookmark(sURL,sTitle) {
 if (document.all && window.external) {
  window.external.AddFavorite (sURL,sTitle);
 else if (window.sidebar) { 
 else {
  alert (''
   +'Cannot programmatically add bookmarks!\n'
   +'Please press Ctrl+D to bookmark this page.'

See also other JavaScript dialogs:

Copyright © 1996-2018,