简体   繁体   English

如何在点击时以编程方式将网页列表添加到浏览器收藏夹中?

[英]How to programmatically add list of web-pages to browser favourites on click?

I currently have a list of useful webpages that I am adding to my web-page. 我目前有一个要添加到我的网页中的有用网页的列表。 I would like to add a link next to each URL that will add it as a bookmark in the users browser. 我想在每个URL旁边添加一个链接,以将其作为书签添加到用户浏览器中。 How can I do this? 我怎样才能做到这一点?

Further to this, how can I add a "Bookmark all links" button to my page ? 除此之外,如何在页面上添加“为所有链接添加书签”按钮?

Bookmarking for the user isn't supported by some major browsers. 一些主要的浏览器不支持为用户添加书签。 You might want to just let the users do it themselves. 您可能只想让用户自己做。 If you insist, however, this post has some code Bookmark on click using jQuery 但是,如果您坚持认为,则此文章在使用jQuery的点击中有一些代码书签

<script language="javascript" type="text/javascript">
$(document).ready(function(){
  $("a.jQueryBookmark").click(function(e){
    e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
    var bookmarkUrl = this.href;
    var bookmarkTitle = this.title;

    if (window.sidebar) { // For Mozilla Firefox Bookmark
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
    } else if(( window.external && window.external.AddFavorite) || document.all) { // For IE Favorite
        window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
    } else if(window.opera) { // For Opera Browsers
        $("a.jQueryBookmark").attr("href",bookmarkUrl);
        $("a.jQueryBookmark").attr("title",bookmarkTitle);
        $("a.jQueryBookmark").attr("rel","sidebar");
    } else { // for other browsers which does not support
         alert('Your browser does not support this bookmark action');
         return false;
    }
  });
});
</script>

This Code is taken from Developersnippets! 该代码摘自Developersnippets!

Chrome does not support such actions, since the security level could be broken. Chrome不支持此类操作,因为可能会破坏安全级别。

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

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