views:

551

answers:

3

Is there any Cross-browser bookmark/add to favorites javascript.

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

+1  A: 

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
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
Aakash Chakravarthy
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
+1  A: 

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

<script type="text/javascript">
  $(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://....

If you need a more complete script, you can always buy one from this page (no, I'm not affiliated with that site... LOL).

Gert G
I wouldn't consider this 'working' - see http://stackoverflow.com/questions/992844/add-to-browser-favourites-bookmarks-from-javascript-but-for-all-browsers-mine-do/993206#993206 for details
Christoph
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
sorry not working for me . I get "Error on page" in IE
Aakash Chakravarthy
A: 

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( ).

ajm