我正在使用 Drupal 构建一个网站。在每个页面的标题上,我希望有一个图像(由我自定义设计),它将充当自定义的“添加到收藏夹”按钮。单击图像应将网站的 URL 添加到用户浏览器的收藏夹(书签)中。这应该适用于所有浏览器,IE7+、FF、Opera、Chrome。 我在网上找不到太多这方面的信息。我认为 javascript 应该可以完成这项工作,但我在 Javascript 方面没有太多经验:)所以我需要你的帮助!
最佳答案
jQuery 版本
$(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>
关于javascript - 如何在我的网站上添加 "Add to Favorites"按钮或链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22101803/