The Tutorials Online

Full Version: JavaScript Bookmark Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Place the following in the head section of the Web page.

Code:
<script type="text/javascript">
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);
}
</script>

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

Code:
<a href="javascript:bookmarksite('Website Name', 'http://www.mywebsite.com')">Bookmark this site!</a>

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.
Reference URL's