views:

53

answers:

2

The "add to favorites" link code that I use, works for firefox but not for Google chrome extensions. What should i use to create a link that adds to Chrome favorites/bookmarks

+1  A: 

There is no way to do it in all browsers. Even in Firefox it doesn't work as expected as it adds a sidebar (on newer versions the user can change that, if he finds the checkbox).

So I am sorry to tell you that you can't. I would provide a social bookmarks widget or ask the user to press CTRL + D to bookmark a page.

Kau-Boy
A: 

Found the bookmarks API for extensions...

This piece of code needed to be inside a function in the background page:

chrome.bookmarks.create({'parentId': bookmarkBar.id,'title': 'Extension bookmarks'},
  function(newFolder) {
    console.log("added folder: " + newFolder.title);
});

Then had to call the function like this:

<a href="javascript:addfav()">Add to bookmarks</a>
David