JavaScript Code to Add Bookmarks/Favorites

We can add a link in the web pages which allows users to add the web page in the Favorites/Bookmarks.
 
To achieve this we need to write a JavaScript function, say "AddToFavorites", and add a hyperlink. And call the JavaScript function "AddToFavorites" by clicking the hyperlink.
 
Use the following code snippet to add the hyperlink to your web page:
  1. <a href="#" onmousedown="AddToFavorites('google.com','http://www.google.co.in')" >Add to Favorites</a>  
And the JavaScript function "AddToFavorites" can be defined as below:
  1.  function AddToFavorites(siteTitle, siteURL)  
  2. {  
  3.     if (window.sidebar)  
  4.     {  
  5.         window.sidebar.addPanel(siteTitle, siteURL,"");  
  6.     }  
  7.     else if(document.all)  
  8.     {  
  9.         window.external.AddFavorite(siteURL, siteTitle);  
  10.     }  
  11.     else if(window.opera && window.print)  
  12.     {  
  13.         return true;  
  14.     }  
  15. }