Last active
December 17, 2019 01:51
-
-
Save foxy-develop/283635de23e43a33f94b1093800bbced to your computer and use it in GitHub Desktop.
This file contains 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
$(document).ready(() => { | |
$("#add_bookmark").click(() => { | |
// Mozilla Firefox Bookmark | |
window.sidebar && window.sidebar.addPanel(location.href, document.title,""); | |
// IE Favorite | |
window.external && window.external.AddFavorite(location.href, document.title); | |
// Opera Hotlist | |
if( window.opera && window.print ) { | |
this.title=document.title; | |
return true; | |
} | |
}); | |
}); | |
//<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a> | |
//second version | |
$(".js-bookmark").click(() => { | |
// Firefox <23 | |
window.sidebar && window.sidebar.addPanel && window.sidebar.addPanel(document.title,window.location.href,''); | |
// Internet Explorer | |
window.external && ('AddFavorite' in window.external) && window.external.AddFavorite(location.href,document.title); | |
// Opera <15 and Firefox >23 | |
if( window.opera && window.print || window.sidebar && ! (window.sidebar instanceof Node) ) { | |
/** | |
* For Firefox <23 and Opera <15, no need for JS to add to bookmarks | |
* The only thing needed is a `title` and a `rel="sidebar"` | |
* To ensure that the bookmarked URL doesn't have a complementary `#` from our trigger's href | |
* we force the current URL | |
*/ | |
triggerBookmark.attr('rel', 'sidebar').attr('title', document.title).attr('href', window.location.href); | |
return true; | |
} else { // For the other browsers (mainly WebKit) we use a simple alert to inform users that they can add to bookmarks with ctrl+D/cmd+D | |
alert('You can add this page to your bookmarks by pressing ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D on your keyboard.'); | |
} | |
// If you have something in the `href` of your trigger | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment