How To HQ

How To Do Almost Anything

You are here: Home / Website Development / JavaScript Bookmark Code
Previous article: Mozilla Thunderbird – Changing the File Location with Windows XP
Next article: Changing Mozilla Thunderbird Password

JavaScript Bookmark Code

March 7, 2006 by Doogie - 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.

  • Home

Categories

  • Automotive
  • Cooking
  • Energy
  • FileZilla Tutorials
  • Financial
  • Health
  • Home Electronics
  • Home Improvement
  • Internet
  • Kindle Tips
  • Miscellaneous
  • Outdoor Sports
  • Personal Computers
  • Pets
  • Security
  • Small Business
  • Thunderbird Tutorials
  • Website Development
  • WordPress
  • Yard & Garden
Content and images are copyrighted by HowToHQ.com and others
Content is intended for personal use only and may not be published or distributed on other websites

Copyright © 2006 - 2023 by HowToHQ.com - All Rights Reserved


Privacy Policy :: Terms of Use