这可以用html按钮为页面添加书签吗?

Jas*_*ngh 7 html javascript jquery bookmarks

这可以用html按钮为页面添加书签吗?

<button>Bookmark This page</button>
Run Code Online (Sandbox Code Playgroud)

<button>Bookmark This page</button>
Run Code Online (Sandbox Code Playgroud)
function onclickfunction(){
  alert('Press Ctrl + D to bookmark this page');
}
Run Code Online (Sandbox Code Playgroud)

此代码指导您如何在 chrome 中为页面添加书签。但我想打开一个对话框,我们在谷歌浏览器中按完成。

Dha*_*ani 6

$(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.');
    }
  });
});
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

  • 已经完成此操作,但我想打开按 Ctrl + D 后出现的对话框。 (2认同)

RAU*_*MAR 4

使用此脚本为您的页面添加书签,您可以在此处引用书签 url
[原始 URL 现在重定向到劫持浏览器后退按钮的诈骗网站。
原始网址为:
http://www.developersnippets.com/2009/05/10/simple-bookmark-script-using-jquery/]

$("button").click(function(e){
    e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
    var bookmarkUrl = "your_bookmark_url";
    var bookmarkTitle = "your_bookmark_title";

    if (window.sidebar) { // For Mozilla Firefox Bookmark
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
    } else if( window.external || document.all) { // For IE Favorite
        window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
    } else { // for other browsers which does not support
         alert('Your browser does not support this bookmark action');
         return false;
    }
  });
Run Code Online (Sandbox Code Playgroud)

  • 自 Firefox 23 起,“window.sidebar.addPanel”不再可用。“window.external.AddFavorite”在 IE 中不再可用。 (2认同)