跨浏览器书签/添加到收藏夹 JavaScript

发布于 2024-09-04 22:16:15 字数 72 浏览 4 评论 0原文

是否有使用 JavaScript 的跨浏览器书签/添加到收藏夹。

搜索了一些列表,但没有一个有效。你能推荐一下吗?

Is there any cross-browser bookmark/add to favorites using JavaScript.

Searched for some list but none is working. Can you please suggest any?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脸赞 2024-09-11 22:16:15

jQuery 版本

JavaScript(根据我在某人网站上找到的脚本修改 - 我只是无法再次找到该网站,所以我无法给予该人信用):

$(document).ready(function() {
  $("#bookmarkme").click(function() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
      window.sidebar.addPanel(location.href,document.title,"");
    } else if(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;
    }
  });
});

HTML:

<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>

IE 将显示错误,如果您不会在服务器上运行它(当将其作为 file://... 查看时,它不允许通过 JavaScript 添加 JavaScript 书签)。

jQuery Version

JavaScript (modified from a script I found on someone's site - I just can't find the site again, so I can't give the person credit):

$(document).ready(function() {
  $("#bookmarkme").click(function() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
      window.sidebar.addPanel(location.href,document.title,"");
    } else if(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;
    }
  });
});

HTML:

<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>

IE will show an error if you don't run it off a server (it doesn't allow JavaScript bookmarks via JavaScript when viewing it as a file://...).

若水般的淡然安静女子 2024-09-11 22:16:15
function bookmark(title, url) {
  if (window.sidebar) { 
    // Firefox
    window.sidebar.addPanel(title, url, '');
  } 
  else if (window.opera && window.print) 
  { 
    // Opera
    var elem = document.createElement('a');
    elem.setAttribute('href', url);
    elem.setAttribute('title', title);
    elem.setAttribute('rel', 'sidebar');
    elem.click(); //this.title=document.title;
  } 
  else if (document.all) 
  { 
    // ie
    window.external.AddFavorite(url, title);
  }
}

我用过这个&在 IE、FF、Netscape 中运行良好。
Chrome、Opera 和 safari 不支持!

function bookmark(title, url) {
  if (window.sidebar) { 
    // Firefox
    window.sidebar.addPanel(title, url, '');
  } 
  else if (window.opera && window.print) 
  { 
    // Opera
    var elem = document.createElement('a');
    elem.setAttribute('href', url);
    elem.setAttribute('title', title);
    elem.setAttribute('rel', 'sidebar');
    elem.click(); //this.title=document.title;
  } 
  else if (document.all) 
  { 
    // ie
    window.external.AddFavorite(url, title);
  }
}

I used this & works great in IE, FF, Netscape.
Chrome, Opera and safari do not support it!

巷子口的你 2024-09-11 22:16:15

使用 ShareThis添加这个?它们具有相似的功能,因此很可能它们已经解决了问题。

AddThis 的代码有一个巨大的 if/else 浏览器版本分支,用于保存收藏夹,但大多数分支最终都会提示用户自己手动添加收藏夹,所以我认为不存在这样的纯 JavaScript 实现。

否则,如果您只需要支持 IE 和 Firefox,则有 IE 的 window.externalAddFavorite( ) 和 Mozilla 的 window.sidebar.addPanel( ) .

How about using a drop-in solution like ShareThis or AddThis? They have similar functionality, so it's quite possible they already solved the problem.

AddThis's code has a huge if/else browser version fork for saving favorites, though, with most branches ending in prompting the user to manually add the favorite themselves, so I am thinking that no such pure JavaScript implementation exists.

Otherwise, if you only need to support IE and Firefox, you have IE's window.externalAddFavorite( ) and Mozilla's window.sidebar.addPanel( ).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文