Tech-Evangelist

Technical Articles, Musings and Opinions from Tech-Evangelist

  • Home
  • About
  • Guidelines
Previous article: Setting up 301 Permanent Redirect on Apache Servers
Next article: Display Hidden Files Using FileZilla – aka FireZilla

JavaScript Bookmark Code

March 2, 2006 By Jonathan - Copyright - All Rights Reserved

Adding a bookmark to your Web site helps assure that visitors who like your web site and wish to return can easily find it once again.

Adding a bookmark is easy to do and does not require any in-depth programming knowledge. It’s a simple matter of cutting and pasting a few snippets of HTML and JavaScript code into a web page script and making a few simple changes to customize it for your site.

Place the following in the head section of the Web page.

<script type="text/javascript">
<!--
function bookmark(url, sitename)
{
  ns="Netscape and FireFox users, use CTRL+D to bookmark this site."
  if ((navigator.appName=='Microsoft Internet Explorer') && 
    (parseInt(navigator.appVersion)>=4)) 
  {
    window.external.AddFavorite(url, sitename);
  }
  else if (navigator.appName=='Netscape') 
  {
    alert(ns);
  }
}
//-->
</script>

Place the following in your HTML code where you want the bookmark link to appear.

<a href="javascript:bookmark('http://www.mydomainname.com/',
'My Site Name');">Bookmark This Site</a>

    (place the line of code shown above on a single line)

Be sure to substitute your site’s domain name for mydomainname.com in the sample code and the name you want to appear in the user’s bookmark in place of My Site Name.

There is one caveat with bookmark code. Because it uses JavaScript, it will not function if JavaScript is disabled in a user’s browser. JavaScript must be enabled for this code to work. That means that there are a small percentage of users who cannot bookmark a site using this code.

Filed Under: Web Site Development

Comments

  1. Jamie says

    May 4, 2007 at 5:11 pm

    I tried finding and using code for this on several pages to add to our website. Yours worked great!! Thanks, you rock!

    Jamie Benti

  2. Mark England says

    October 17, 2007 at 3:07 pm

    Ditto what Jamie stated. Your code worked perfect.

    Thanks

  3. kannan says

    January 23, 2008 at 10:53 pm

    without using ctrl+D, in netscape is there any other javascript code to bookmark the page by clicking the link.

  4. TE says

    January 28, 2008 at 6:11 pm

    Hi kannan

    Netscape is officially dead. I have been looking for something that works with FireFox, but have not found anything that works reliably. If anyone knows of a FireFox JavaScript function to add bookmarks, let me know and I will modify the code. I am aware of the window.sidebar routine, but that does not yield the same results.

  5. Mary says

    March 30, 2008 at 6:49 pm

    Hi,

    This worked like a charm! Thank you so much.
    Best,
    Mary

  6. Al Marr says

    June 14, 2008 at 12:14 pm

    Kannan,

    Perhaps you can modify the following code, as it still makes Firefox bookmarks open in the sidebar. Sure, you can click on the link properties and uncheck “Load this bookmark in the sidebar”, but what a hassle to always have to do that!

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

  7. M Chatter says

    June 16, 2008 at 10:06 pm

    We have a large userbase of firefox users. Does anyone know of a graceful way to do this for firefox?

    M Chatter

  8. Brian Mason says

    October 11, 2008 at 1:45 am

    Hi
    Has anyone come up with a code to stop Firefox bookmarked pages opening up in the side bar.

    IE works well but it’s a pain with Firefox.

    Brian

  9. Abdul Wahab says

    December 16, 2008 at 3:37 am

    Thanks, it works. I hope many of my visitors will use them.

  10. Cody says

    January 31, 2009 at 10:35 am

    Works perfect. Thanks!

  11. Christopher says

    February 3, 2009 at 1:12 pm

    Nice, it works, and well!!!

    Thanks

  12. Shobin says

    March 10, 2009 at 6:53 am

    Fantastic work! I tried many codes, but none works as fine as yours. Thanks!!

  13. Shane says

    November 12, 2009 at 3:01 pm

    This code works in both IE and Firefox

    *** EDITED***

    Thanks, Shane. The script did not come through properly, but we recognized it as a Dynamic Drive bookmark script. You can find the original script here if anyone wants to experiment with it:

    Bookmark Site Script

  14. vijay says

    March 22, 2011 at 5:28 am

    hey… friends… this code worked well… thanks a lot….

  15. Ankit goyal says

    July 22, 2011 at 12:46 am

    It worked

Categories

  • Affiliate Marketing
  • CSS Tutorials
  • FileZilla Tutorials
  • Home Theater
  • Internet Marketing
  • Internet Technology
  • Kindle Tips
  • MySQL Tutorials
  • Online Auction Tips
  • Paint Shop Pro Tutorials
  • PHP Tutorials
  • Tech News
  • Thunderbird Tutorials
  • Video Production
  • Web Site Development
  • WordPress Tutorials
follow me on Twitter
Content and images are copyrighted by Tech-Evangelist.com and others

© 2021 Tech-Evangelist.com - All Rights Reserved
Posted code samples are free to use. Do not reproduce or republish articles or content on another web site.

Privacy Policy : Terms of Use