Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add bookmark
$("a#bookmark").click(function(e)
{
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if ($.browser.mozilla) // For Mozilla Firefox Bookmark
{
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
}
else if ($.browser.msie) // For IE Favorite
{
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
}
else if ($.browser.opera ) // For Opera Browsers
{
$(this).attr("href",bookmarkUrl);
$(this).attr("title",bookmarkTitle);
$(this).attr("rel","sidebar");
$(this).click();
}
else // for other browsers which does not support
{
alert('Please hold Command+D (On Mac OS) or CTRL+D (On Windows and Linux) and click the link to bookmark it in your browser.');
}
return false;
});
$("a.jQueryBookmark").click(function(e)
{
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
// For Mozilla Firefox Bookmark
if (window.sidebar)
{
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
}
// For IE Favorite (We have to manually filter chrome out of here because it doesn't allow
// JS to add bookmarks)
else if ((window.external || document.all) && !$.browser.chrome)
{
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
}
// For Opera Browsers
else if (window.opera)
{
$("a.jQueryBookmark").attr("href",bookmarkUrl);
$("a.jQueryBookmark").attr("title",bookmarkTitle);
$("a.jQueryBookmark").attr("rel","sidebar");
}
// For other browsers which do not support adding bookmarks through JavaScript
else
{
alert('Please hold Command+D (On Mac OS) or CTRL+D (On Windows and Linux) and click the link to bookmark it in your browser.');
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment