Created
November 15, 2011 20:28
-
-
Save esses/1368231 to your computer and use it in GitHub Desktop.
Quick Cross-Browser jQuery Bookmark Script
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
$('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.'); | |
} | |
}); |
window.sidebar.addPanel() was removed from firefox as of version 23.
to work for firefox >23 , add rel="sidebar" in your tag.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.