Skip to content

Instantly share code, notes, and snippets.

@esses
Created November 15, 2011 20:28
Show Gist options
  • Select an option

  • Save esses/1368231 to your computer and use it in GitHub Desktop.

Select an option

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

oncode commented Feb 7, 2013

Copy link
Copy Markdown

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

ph9sam commented Sep 24, 2013

Copy link
Copy Markdown

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

@technoknol

Copy link
Copy Markdown

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

@mortyobnoxious

Copy link
Copy Markdown

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