9

I setting up a website and would like to add a simple button to allow a visitor add my page to their bookmarks/favorites. There is a way to do this using javascript? And there is a cross-browser solution?

All of previous answers in Stack Overflow doesn't work anymore, tried all of most recent and some of really old of them, but had no success. This is not a duplicate question.

I tried a lot of solutions, but the last one was:

$(function() {
  $('#bookmarkme').click(function() {
    if (window.sidebar && window.sidebar.addPanel) { // Mozilla Firefox Bookmark
      window.sidebar.addPanel(document.title, window.location.href, '');
    } else if (window.external && ('AddFavorite' in 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;
    } else { // webkit - safari/chrome
      alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
    }
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>
Sunfloro
  • 730
  • 1
  • 8
  • 12
  • Possible duplicate of [is this possible to bookmark a page with html button?](https://stackoverflow.com/questions/45415678/is-this-possible-to-bookmark-a-page-with-html-button) – Andreas Feb 19 '19 at 05:54
  • 1
    All of the solutions in this link doesn't work in firefox and chrome (probably doesn't work in any browser anymore), tried all in this post, no exceptions. – Sunfloro Feb 19 '19 at 05:57
  • 4
    All of the browsers I use already have a built-in button that lets me add the current page to my bookmarks. Why have another one in HTML in the page content? Also, I wouldn't be surprised if browsers no longer allow this at all - they shouldn't, because letting JS add bookmarks is a security concern. – nnnnnn Feb 19 '19 at 06:07
  • Possible duplicate of [AddFavorite JS doesn't work with chrome](https://stackoverflow.com/questions/22085812/addfavorite-js-doesnt-work-with-chrome) – Ouroborus Feb 19 '19 at 09:31
  • This no longer works for security reasons. And God help you if you use jQuery. – ChrisN Aug 23 '21 at 23:25

1 Answers1

31

Once upon a time, this could be done. But unscrupulous sites would abuse the capability, forcibly bookmarking sites the user didn't want bookmarked. Now it is no longer possible for pages to add bookmarks on behalf of the user.

Ouroborus
  • 16,237
  • 4
  • 39
  • 62