如何创建“为此页面添加书签";按钮? [英] How to create a "Bookmark this page" button?

查看:51
本文介绍了如何创建“为此页面添加书签";按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个网站,并希望添加一个简单的按钮,以允许访问者将我的页面添加到他们的书签/收藏夹中.有一种方法可以使用javascript吗?还有跨浏览器的解决方案吗?

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?

Stack Overflow中的所有先前答案不再起作用,尝试了所有最新方法以及其中一些确实很老的方法,但均未成功.这不是重复的问题.

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>

推荐答案

从前,这可以做到.但是不道德的网站会滥用此功能,强行为用户不希望添加书签的网站添加书签.现在页面不再可以代表用户添加书签.

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.

这篇关于如何创建“为此页面添加书签";按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆