inicio sindicaci;ón
Jochem Prins: about search, Web2.0 and things I like

Archive for Programming

Cross-browser ‘bookmark this site’ script

I always thought that only Microsoft Internet Explorer supported a ‘bookmark this site’ functionality. By doing some research on the web I found a few code snippets that did the trick for other browsers as well. I compiled these scripts together in the following bookmarkthis(title, url) function. It’s completely cross-browser (compatible with IE4+, Firefox 1.x+ and Opera7+). Have fun with it!


function bookmarkthis(title,url) {
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
}