Cross-browser bookmark/add to favorites JavaScript

Aakash Chakravarthy picture Aakash Chakravarthy · Jun 11, 2010 · Viewed 179.4k times · Source

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

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

Answer

Gert Grenander picture Gert Grenander · Jun 11, 2010

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://...).