简体   繁体   English

如何创建“收藏此页面”按钮?

[英]How to create a "Bookmark this page" button?

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?有没有办法使用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. Stack Overflow 中以前的所有答案都不再有效,尝试了所有最新的和一些非常旧的答案,但没有成功。 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>

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.现在,页面不再可能代表用户添加书签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM