Return to Snippet

Revision: 62625
at March 3, 2013 20:51 by apphp-snippets


Initial Code
<script type="text/javascript">
function CreateBookmarkLink(){
    var title = document.title;
    var url = document.location.href;
 
    if(window.sidebar){
        /* Mozilla Firefox Bookmark */
        window.sidebar.addPanel(title, url, "");
    }else if(window.external){
        /* IE Favorite */
        window.external.AddFavorite(url, title);
    }else if(window.opera && window.print) {
        /* Opera Hotlist */
        alert("Press Control + D to bookmark");
        return true;
    }else{
        /* Other */
        alert("Press Control + D to bookmark");
    }
}
</script>
 
<a href="javascript:CreateBookmarkLink();">Add to Favorites/Bookmark</a>

Initial URL
http://www.apphp.com/index.php?snippet=javascript-add-to-favorites-button

Initial Description
Most today's web browsers like Firefox (Ctrl+D), Opera (Ctrl+T) and IE (Ctrl+D) provide a keyboard shortcuts to enable users bookmark their favorite pages. But if you want to provide your visitors with a "Bookmark this page" link they can click you may use the code below: It works in IE, FireFox and Opera. Clicking on the link prompts the user with a dialog box to add the specified URL to the Favorites list.

Initial Title
Create Add to Favorites/Bookmark button in Javascript

Initial Tags
button

Initial Language
JavaScript