6

I have tried using JavaScript "AddFavorite" function in my code, but it does not work in Safari. It works in IE, I think I remember Firefox, but nothing I have tried seems to work in Safari. All I want to do is have a link on my website that people can click on and it automatically creates a bookmark in their bookmarks folder/bookmark bar.

Does this entail Applescript or something like it? Or a deeper programming language I am unaware of?

<a href="javascript:bookmarksite('Name', 'website.com')">
Imad Alazani
  • 6,688
  • 7
  • 36
  • 58
bethany
  • 71
  • 1
  • 1
  • 3
  • I have tried what I have stated above. JavaScript. – bethany Jun 29 '12 at 16:04
  • **facepalm**. Can you please provide the CODE that you've tried? – Evan Davis Jun 29 '12 at 16:06
  • @BethanyMichelleStephens what is the code of `bookmarksite` function? Please edit your question with this (don't post it in a comment as the formatting will be removed) Not that it really matters, some browsers just don't allow it. see my answer below. – sachleen Jun 29 '12 at 16:11
  • @BethanyMichelleStephens no, the actual code of the function. This is just the call to it. Find somewhere in your code where it has something like `function bookmarksite(title, url) { code here }` – sachleen Jun 29 '12 at 16:16
  • Have you readout this one? http://stackoverflow.com/questions/10033215/add-to-favorites-button/10033250#10033250 – Just code Nov 09 '13 at 06:44

5 Answers5

3

From the apple forums: forum-link

On the Mac side at least, Safari does not allow a website to add a bookmark. I'm pretty sure the same behaviour is in the Windows version as well.

sachleen
  • 30,730
  • 8
  • 78
  • 73
Tarantoga
  • 551
  • 3
  • 4
2

I've been down this road, and what I discovered was that Safari does NOT allow bookmarks to be made with JavaScript:

Apple Forum

bytes forum

They consider it unsafe. As frustrating as this is, I get their point.

Dave Alperovich
  • 32,320
  • 8
  • 79
  • 101
0

Unfortunately, most things like this tend to be browser-specific, and picky.

my JS is about level 0, but i did find this on an old article here:

One specifically for Chrome: Add to favourites link for Google Chrome

And another on a cross-browser bookmark link: Cross-browser bookmark/add to favorites javascript

Hope between the previous comment and these links, you get what you needed.

Community
  • 1
  • 1
0

Chrome and Safari does not allow it for clear security reason.

You could usee a script like this:

http://www.dynamicsitesolutions.com/javascript/add-bookmark-script/

which handles many browser and has a nice fallback: show a browser customized alert with instructuion message.

Es: in chrome it says: "Ctrl+D to add as bookmark"

giammin
  • 18,620
  • 8
  • 71
  • 89
-1

In IE something similar to the following would work: (MSDN)

window.external.AddFavorite(location.href, document.title);

However, this won't work in other browsers. In Firefox, I believe you can use

window.sidebar.addPanel(document.title, location.href, '');

to create a sidebar panel (not a real bookmark) but as far as I know Chrome and Safari do not allow Javascript to automatically create bookmarks. For those, I recommend giving the user the instructions to do it manually:

  • drag a link to their bookmarks
  • pressing Ctrl + D to add a bookmark
  • Clicking + or star icon in the toolbar
sachleen
  • 30,730
  • 8
  • 78
  • 73