admin管理员组

文章数量:1278793

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')">

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.')">
Share Improve this question edited Nov 7, 2013 at 0:34 Chamaququm 6,7287 gold badges38 silver badges58 bronze badges asked Jun 29, 2012 at 15:54 bethanybethany 711 gold badge1 silver badge3 bronze badges 5
  • I have tried what I have stated above. JavaScript. – bethany Commented Jun 29, 2012 at 16:04
  • facepalm. Can you please provide the CODE that you've tried? – Evan Davis Commented Jun 29, 2012 at 16:06
  • @BethanyMichelleStephens what is the code of bookmarksite function? Please edit your question with this (don't post it in a ment as the formatting will be removed) Not that it really matters, some browsers just don't allow it. see my answer below. – sachleen Commented Jun 29, 2012 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 Commented Jun 29, 2012 at 16:16
  • Have you readout this one? stackoverflow./questions/10033215/add-to-favorites-button/… – Just code Commented Nov 9, 2013 at 6:44
Add a ment  | 

5 Answers 5

Reset to default 3 +250

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.

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.

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 ment and these links, you get what you needed.

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

You could usee a script like this:

http://www.dynamicsitesolutions./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"

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 remend 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

本文标签: javascriptCreate a Bookmark link that works in SafariStack Overflow