Search code examples
javascriptjqueryhtmlbookmarks

is this possible to bookmark a page with html button?


is this possible to bookmark a page with html button?

<button>Bookmark This page</button>

function onclickfunction(){
  alert('Press Ctrl + D to bookmark this page');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="onclickfunction()">Bookmark this page</button>

this code instruct you to how to bookmark a page in chrome. but i want to open a dialog box where we press finished in google chrome.


Solution

  • Use this script to bookmark your page, you can reference here bookmark a url
    [Original URL now redirects to a scam website that hijacks the browser's back button.
    Original URL was:
    http://www.developersnippets.com/2009/05/10/simple-bookmark-script-using-jquery/]

    $("button").click(function(e){
        e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
        var bookmarkUrl = "your_bookmark_url";
        var bookmarkTitle = "your_bookmark_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 { // for other browsers which does not support
             alert('Your browser does not support this bookmark action');
             return false;
        }
      });