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

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

本文关键字:添加 列表 网页 浏览器 收藏夹 方式 单击 编程      更新时间:2023-09-26

我目前有一个有用的网页列表,正在添加到我的网页中。我想在每个URL旁边添加一个链接,将其作为书签添加到用户浏览器中。我该怎么做?

除此之外,我如何在我的页面上添加"为所有链接添加书签"按钮?

一些主要浏览器不支持为用户添加书签。你可能只想让用户自己做。如果你坚持,然而,这篇文章有一些代码书签点击使用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>

此代码取自Developersnippets!

Chrome不支持这样的操作,因为安全级别可能会被破坏。