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!
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.
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.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With