Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add an "Add to Favorites" button or link on my website?

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!

like image 590
webmaniacgr Avatar asked Apr 05 '12 17:04

webmaniacgr


People also ask

How do you add a favorite in HTML?

Create a Bookmark in HTML Bookmarks can be useful if a web page is very long. To create a bookmark - first create the bookmark, then add a link to it.

How do I add a website to my favorites in browser?

Type your login URL into the address bar at the top of your browser window, then press Enter on your keyboard. Once the login page loads, click on the star icon in the top right corner of the screen. Select Add to Favorites. Give the bookmark a name, and select a location where you would like the bookmark saved.


2 Answers

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>
like image 76
iambriansreed Avatar answered Oct 02 '22 05:10

iambriansreed


This code is the corrected version of iambriansreed's answer:

<script type="text/javascript">     $(function() {         $("#bookmarkme").click(function() {             // Mozilla Firefox Bookmark             if ('sidebar' in window && 'addPanel' in window.sidebar) {                  window.sidebar.addPanel(location.href,document.title,"");             } else if( /*@cc_on!@*/false) { // IE Favorite                 window.external.AddFavorite(location.href,document.title);              } else { // webkit - safari/chrome                 alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');             }         });     }); </script> 
like image 33
Handsome Nerd Avatar answered Oct 02 '22 04:10

Handsome Nerd