Created
August 5, 2013 14:46
-
-
Save obahareth/6156458 to your computer and use it in GitHub Desktop.
Add bookmark
This file contains hidden or 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(); // 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; | |
}); |
This file contains hidden or 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.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