Create Add to Favorites/Bookmark button in Javascript


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. function CreateBookmarkLink(){
  3. var title = document.title;
  4. var url = document.location.href;
  5.  
  6. if(window.sidebar){
  7. /* Mozilla Firefox Bookmark */
  8. window.sidebar.addPanel(title, url, "");
  9. }else if(window.external){
  10. /* IE Favorite */
  11. window.external.AddFavorite(url, title);
  12. }else if(window.opera && window.print) {
  13. /* Opera Hotlist */
  14. alert("Press Control + D to bookmark");
  15. return true;
  16. }else{
  17. /* Other */
  18. alert("Press Control + D to bookmark");
  19. }
  20. }
  21. </script>
  22.  
  23. <a href="javascript:CreateBookmarkLink();">Add to Favorites/Bookmark</a>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.