Last active
April 10, 2017 08:44
-
-
Save danwarfel/abb8135c2cebffc37da2 to your computer and use it in GitHub Desktop.
Add a Cross-Browser “Add to Favorites” (Bookmark) Button to Your Website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Add to Bookmarks Cross-Browser Demo</title> | |
<!-- from https://www.thewebflash.com/how-to-add-a-cross-browser-add-to-favorites-bookmark-button-to-your-website/ --> | |
<style> | |
#bookmark-this { | |
padding: 5px 10px; | |
font-size: 12px; | |
background: #f0ad4e; | |
color: #fff; | |
border: 1px solid #eea236; | |
border-radius: 4px; | |
text-decoration: none; | |
text-shadow: 0 -1px 0 rgba(0, 0, 0, .2); | |
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2); | |
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2); | |
-webkit-user-select:none; | |
-moz-user-select:none; | |
-ms-user-select:none; | |
user-select:none; | |
} | |
#bookmark-this:hover { | |
background: #ec971f; | |
border: 1px solid #d58512; | |
text-decoration: none; | |
} | |
#bookmark-this:active { | |
border: 1px solid #d58512; | |
-webkit-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2); | |
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2); | |
background: #ec971f; | |
} | |
</style> | |
<!-- Add to Homescreen callout for mobile browsers https://github.com/cubiq/add-to-homescreen --> | |
<link rel="stylesheet" href="css/addtohomescreen.css"> | |
<script src="js/addtohomescreen.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script> | |
jQuery(document).ready(function($) { | |
$('#bookmark-this').click(function(e) { | |
var bookmarkURL = window.location.href; | |
var bookmarkTitle = document.title; | |
if ('addToHomescreen' in window && window.addToHomescreen.isCompatible) { | |
// Mobile browsers | |
addToHomescreen({ autostart: false, startDelay: 0 }).show(true); | |
} else if (window.sidebar && window.sidebar.addPanel) { | |
// Firefox version < 23 | |
window.sidebar.addPanel(bookmarkTitle, bookmarkURL, ''); | |
} else if ((window.sidebar && /Firefox/i.test(navigator.userAgent)) || (window.opera && window.print)) { | |
// Firefox version >= 23 and Opera Hotlist | |
$(this).attr({ | |
href: bookmarkURL, | |
title: bookmarkTitle, | |
rel: 'sidebar' | |
}).off(e); | |
return true; | |
} else if (window.external && ('AddFavorite' in window.external)) { | |
// IE Favorite | |
window.external.AddFavorite(bookmarkURL, bookmarkTitle); | |
} else { | |
// Other browsers (mainly WebKit - Chrome/Safari) | |
alert('Press ' + (/Mac/i.test(navigator.userAgent) ? 'Cmd' : 'Ctrl') + '+D to bookmark this page.'); | |
} | |
return false; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<a id="bookmark-this" href="#" title="Bookmark This Page">Bookmark This Page</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment