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();
  }
}

10 thoughts on “Cross-browser ‘bookmark this site’ script

  1. Niels says:

    Thanks! It works indeed!

    Btw, I always advise my visitors to press ctrl-D when they like my site. That’s a quick way to add the url to your bookmarks as well.

  2. C L says:

    Netscape (8.1.2) seems to want to add it to Sidebar instead of bookmarks.
    Opera (9.10) doesn’t seem to do anything.

  3. jochem says:

    @C L,
    Thanks, in turns out that Firefox opens the bookmarks in the sidebar as well. I didn’t check that… Too bad.
    I’ll keep my eyes open for any other possibilities.

  4. Siggi says:

    Hi.

    And, what’s on with other possibilities?
    🙂

    Has anyone find a snippet?

  5. isoveli says:

    Niels: Yes, if they’re using IE, it doesn’t bookmark i any other (real) browser

  6. Layla says:

    Basically identical to the script posted elsewhere…
    http://www.dynamicdrive.com/dynamicindex9/addbook.htm
    🙂

  7. Samiun says:

    How to use this function?

  8. miele says:

    nobody seems to know how to bookmark in firefox without using the sidebar. Isn’t there any way to bookmark in firefox properly?

  9. Suhail says:

    hi
    well i have used this script, but it doent work in opera 9.
    it didnt bookmark the url.
    please give me a script which also run in opera

Leave a Reply

Your email address will not be published. Required fields are marked *