Skip to content

Instantly share code, notes, and snippets.

@esses
Created November 15, 2011 20:28
Show Gist options
  • Save esses/1368231 to your computer and use it in GitHub Desktop.
Save esses/1368231 to your computer and use it in GitHub Desktop.
Quick Cross-Browser jQuery Bookmark Script
$('a#bookmark').click(function(e){
e.preventDefault();
var bookmarkURL = this.href;
var bookmarkTitle = this.title;
try {
if (window.sidebar) { // moz
window.sidebar.addPanel(bookmarkTitle, bookmarkURL, "");
} else if (window.external || document.all) { // ie
window.external.AddFavorite(bookmarkURL, bookmarkTitle);
} else if (window.opera) { // duh
$('a#bookmark').attr('href',bookmarkURL);
$('a#bookmark').attr('title',bookmarkTitle);
$('a#bookmark').attr('rel','sidebar');
}
} catch (err) { // catch all incl webkit
alert('Sorry. Your browser does not support this bookmark action. Please bookmark this page manually.');
}
});
@oncode
Copy link

oncode commented Feb 7, 2013

if you try this at safari, the operation will fail silently and not alert something. A catch statement catches only exceptions, but there won't be any, because the if statements prevent any.

@ph9sam
Copy link

ph9sam commented Sep 24, 2013

window.sidebar.addPanel() was removed from firefox as of version 23.

@technoknol
Copy link

to work for firefox >23 , add rel="sidebar" in your tag.

@mortyobnoxious
Copy link

is it possible to make this unchecked?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment