Firefox add to favorites code


I have updated the javascript code, below, for my website as I noticed the add to favourites link didn’t bookmark websites in Firefox. I have now updated the code so that this is compatible with both Firefox and IE but I’ve noticed this is opening the url in the sidebar window instead of a full browser page. If anyone knows how to fix this please let me know as so far I’ve only found examples which do the same or only work in IE.

Firefox add to favorites code:
<script type=”text/javascript”>
function bookmarksite(){
if (document.all)
window.external.AddFavorite(location.href, document.title);
else if (window.sidebar)
window.sidebar.addPanel(document.title, location.href, “”)
}
<% /script>
<% a href=”javascript:bookmarksite()”> Add to favorites< /a>

Kevin Gibbons is Founder/Director of Strategy at SEOptimise. Kevin is well known within the search industry as a blogger for sites such as Search Engine Land, Econsultancy and Search Engine Watch. Kevin is also a frequent SEO speaker at a number of conferences including Search Marketing Expo (SMX), Search Engine Strategies (SES), a4uexpo, SAScon and BrightonSEO.

11 Comments

Got something to say? Feel free, I want to hear from you! Leave a Comment

  1. Anonymous says:

    thanks, works well

  2. Pradeep says:

    Do you know the code for Safari and Opera? just curious.

  3. Anonymous says:

    Not tested but I believe the code for safari would be something like:

    a href=http://www.google.com” title=”Google web search” rel=”sidebar”

    As for Safari I have no idea, I found this page while googling how to do it in Safari.

  4. brandon says:

    it dosent work

  5. offshore software development says:

    thanks for code..i will use it.

  6. Anju says:

    good script.. I will use it in one of my sites!

  7. Michael says:

    Nothing works for me. If someone can send me a code that works, I will pay!

  8. sergey says:

    edit quotes after you copy-paste the code and it will work fine..

  9. OnLine says:

    I tested it and it doesnt wor in mozila firefox 3.05

  10. OnLine says:

    I found a script that works:

    /***********************************************
    * Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    /* Modified to support Opera */
    function bookmarksite(title,url){
    if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, “”);
    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();
    }
    else if(document.all)// ie
    window.external.AddFavorite(url, title);
    }

    Bookmark this site!

  11. Alexei says:

    @Online
    Thanks a lot for the script, i just think that the order of the if statements should be changed to ie, firefox and opera at the end

Leave a Comment

Let us know your thoughts on this post but remember to play nicely folks!