2

Is it possible to add bookmarks to a browser with in my web page? For example when I click a button in the page, a bookmark then be added to the browser.

I wonder is javascript the best choice and does the solution change with different browsers?

To implement this, do I need to ask for permissions from the users?

jinglei
  • 3,269
  • 11
  • 27
  • 46

1 Answers1

1

This will do the job.

<script type="text/javascript"> 

function bookmarksite(title,url) { 
   // Internet Explorer
   if(document.all)
   {
       window.external.AddFavorite(url, title); 
   }
   // Google Chrome
   else if(window.chrome){
      alert("Press Ctrl+D to add bookmark");
   }
   // Firefox
   else if (window.sidebar)
   {
       window.sidebar.addPanel(title, url, ""); 
   }
   // Opera
   else if(window.opera && window.print)
   {
      var elem = document.createElement('a'); 
      elem.setAttribute('href',url); 
      elem.setAttribute('title',title); 
      elem.setAttribute('rel','sidebar'); 
      elem.click(); 
   }
} 
</script>

<a href="javascript:bookmarksite('TITLE', 'URL')">ADD BOOKMARK</a>
Inpyo Jeon
  • 220
  • 1
  • 7