如何添加“添加到收藏夹”按钮或链接在我的网站上? [英] How do I add an "Add to Favorites" button or link on my website?

查看:171
本文介绍了如何添加“添加到收藏夹”按钮或链接在我的网站上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Drupal建立一个网站。在每个页面的标题上,我希望有一个图像(由我设计的自定义图像),这将用作自定义的添加到收藏夹按钮。点击图像应该将网站的URL添加到用户浏览器的收藏夹(书签)。这应该适用于所有浏览器,IE7 +,FF,Opera,Chrome。
我无法在网上找到很多信息。我认为javascript应该可以完成这项工作,但是我没有太多的Javascript经验:)所以我需要你的帮助! 解决方案

jQuery版本



$(function(){$('#bookmarkme' ).click(function(){if(window.sidebar& window.sidebar.addPanel){// Mozilla Firefox书签window.sidebar.addPanel(document.title,window.location.href,'');} else if(window.external&('window.external'中的'AddFavorite')){// IE Favorite window.external.AddFavorite(location.href,document.title);} else if(window.opera&& amp; ; window.print){// Opera Hotlist this.title = document.title; return true;} else {// webkit - safari / chrome alert('Press'+(navigator.userAgent.toLowerCase()。indexOf( MAC)!= -1?‘命令/加利福尼亚’:CTRL)+ + d到收藏此页); < script src =}});});

 

I'm building a website using Drupal. On the header of each page I want to have a single image (custom designed by me) which would act as a custom "Add to Favorites" button. Clicking on the image should add the website's URL to the user browser's favorites (bookmarks). This should work for all browsers, IE7+, FF, Opera, Chrome. I wasn't able to find much information for this online. I suppose that javascript should do the job but I don't have much experience in Javascript :) so I need your help!

解决方案

jQuery Version

$(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>

这篇关于如何添加“添加到收藏夹”按钮或链接在我的网站上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆