80

Is there any cross-browser bookmark/add to favorites using JavaScript.

Searched for some list but none is working. Can you please suggest any?

6
  • I'm thinking no. Bookmarks/favorites should be under the control of the user, imagine if any site you visited could insert itself into your bookmarks with just some javascript.
    – bwarner
    Jun 11, 2010 at 17:18
  • I am not asking for automatic bookmarking. A button when clicked should bookmark the current page. I saw many scripts but none were cross browser support Jun 11, 2010 at 17:21
  • OK, so you're asking for something that prompts the user whether they want to add your site to bookmarks. That's a bit different...
    – bwarner
    Jun 11, 2010 at 17:27
  • 18
    To be honest: if a user needs a button to bookmark the site chances are he/she does not know how bookmarks work. Users who normally use bookmarks know that you can press CTRL+D, drag the little site icon on the bookmark bar, use the menu etc etc.. I find that putting a "bookmark us!" button seems a bit retro, so to say. Just make a good website with contents that pushes the user to bookmark it and you won't need any button. (Just my 2¢ on this type of situations, then it's you who have to decide what buttons to put on your website!)
    – nico
    Jun 12, 2010 at 6:41
  • 6
    I am not putting a button in my website ! I am creating a wordpress plugin. Users who install it get a button to bookmark the current page like the "sociable" plugin Jun 12, 2010 at 10:00

3 Answers 3

56

jQuery Version

JavaScript (modified from a script I found on someone's site - I just can't find the site again, so I can't give the person credit):

$(document).ready(function() {
  $("#bookmarkme").click(function() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
      window.sidebar.addPanel(location.href,document.title,"");
    } else if(window.external) { // IE Favorite
      window.external.AddFavorite(location.href,document.title); }
    else if(window.opera && window.print) { // Opera Hotlist
      this.title=document.title;
      return true;
    }
  });
});

HTML:

<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>

IE will show an error if you don't run it off a server (it doesn't allow JavaScript bookmarks via JavaScript when viewing it as a file://...).

9
  • 2
    I wouldn't consider this 'working' - see stackoverflow.com/questions/992844/… for details
    – Christoph
    Jun 11, 2010 at 19:00
  • actually, the FF situation has somewhat improved since my answer because of UI changes, ie the user can now remove the option to open the link in the sidebar when adding the bookmark
    – Christoph
    Jun 11, 2010 at 19:04
  • sorry not working for me . I get "Error on page" in IE Jun 12, 2010 at 5:20
  • 2
    Doesn't this require an external js library as well?
    – Necrolyte2
    Jun 20, 2013 at 22:05
  • 4
    This answer seems to be obsolete, any update would be welcome.
    – sinsedrix
    Dec 1, 2017 at 10:53
13
function bookmark(title, url) {
  if (window.sidebar) { 
    // Firefox
    window.sidebar.addPanel(title, url, '');
  } 
  else if (window.opera && window.print) 
  { 
    // Opera
    var elem = document.createElement('a');
    elem.setAttribute('href', url);
    elem.setAttribute('title', title);
    elem.setAttribute('rel', 'sidebar');
    elem.click(); //this.title=document.title;
  } 
  else if (document.all) 
  { 
    // ie
    window.external.AddFavorite(url, title);
  }
}

I used this & works great in IE, FF, Netscape. Chrome, Opera and safari do not support it!

3

How about using a drop-in solution like ShareThis or AddThis? They have similar functionality, so it's quite possible they already solved the problem.

AddThis's code has a huge if/else browser version fork for saving favorites, though, with most branches ending in prompting the user to manually add the favorite themselves, so I am thinking that no such pure JavaScript implementation exists.

Otherwise, if you only need to support IE and Firefox, you have IE's window.externalAddFavorite( ) and Mozilla's window.sidebar.addPanel( ).

Not the answer you're looking for? Browse other questions tagged or ask your own question.