Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bookmark on click using jQuery

Is there a way to save the current page as a bookmark (through jQuery or otherwise) when a specific button is clicked?

like image 312
conbask Avatar asked Apr 29 '11 07:04

conbask


4 Answers

<script language="javascript" type="text/javascript">
$(document).ready(function(){
  $("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;

    if (window.sidebar) { // For Mozilla Firefox Bookmark
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
    } else if( window.external || document.all) { // For IE Favorite
        window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
    } else if(window.opera) { // For Opera Browsers
        $("a.jQueryBookmark").attr("href",bookmarkUrl);
        $("a.jQueryBookmark").attr("title",bookmarkTitle);
        $("a.jQueryBookmark").attr("rel","sidebar");
    } else { // for other browsers which does not support
         alert('Your browser does not support this bookmark action');
         return false;
    }
  });
});
</script>

This Code is taken from Developersnippets!

/e:

Chrome does not support such actions, since the security level could be broken.

like image 68
bastianwegge Avatar answered Oct 06 '22 15:10

bastianwegge


Since Chrome does not support such action, a solution could be to check first if the browser in use it's Chrome and if so to alert the user that the bookmark function is not supported. Then for other cases the script provided on DevelopersSnippets works fine.

Example:

   $("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 (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { 
            alert("This function is not available in Google Chrome. Click the star symbol at the end of the address-bar or hit Ctrl-D (Command+D for Macs) to create a bookmark.");      
    }else if (window.sidebar) { // For Mozilla Firefox Bookmark
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
    } else if( window.external || document.all) { // For IE Favorite
        window.external.AddFavorite( bookmarkUrl, bookmarkTitle);          
    } else if(window.opera) { // For Opera Browsers
        $("a.bookmark").attr("href",bookmarkUrl);
        $("a.bookmark").attr("title",bookmarkTitle);
        $("a.bookmark").attr("rel","sidebar");
    } else { // for other browsers which does not support
         alert('Your browser does not support this bookmark action');
         return false;
    }
  });
like image 39
Alessandro Incarnati Avatar answered Oct 06 '22 14:10

Alessandro Incarnati


Try this:

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
} 
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}
like image 22
Harry Joy Avatar answered Oct 06 '22 15:10

Harry Joy


I think jquery Bookmark plugin is what you are looking for . jBrowserBookmark allows you to add functionality to a site which allows a page to be added to the browsers boookmark list. This feature is supported by Internet Explorer, Firefox, Opera and Konqueror browsers.You can get it here

like image 40
Abdul Kader Avatar answered Oct 06 '22 16:10

Abdul Kader