Posted By

apphp-snippets on 03/03/13


Tagged

button FavoritesBookmark


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ronan
Abiotic


Create Add to Favorites/Bookmark button in Javascript


 / Published in: JavaScript
 

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

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.

  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>

Report this snippet  

You need to login to post a comment.