Adam - Thu April 2, 2009 11:02 PM

Add to Bookmarks Javascript    

Our Javascript Mission!

In this article our mission is to build a very light and simple script that will allow your users to add a page of your website to their browser bookmarks. You’ll see this type of thing on many sites and if you have good content on your website your users might appreciate the extra ease in bookmarking your pages.

The Javascript

Our bookmark script will be totally self-contained to make things easy for this article. All code will be contained completely in the link. Check the code below…

<a href="javascript:if(document.all)
window.external.AddFavorite(location.href,document.title);
else if(window.sidebar)window.sidebar.addPanel
(document.title,location.href,'');">
Bookmark this site!</a>

Try this link…Bookmark this site!

The script contained in the link fills in the page title and the URL for your user on contemporary browsers. Browsers that can’t do it will do nothing. If your site is set up with any type of server side includes to reuse common code you could stick the script in one of the includes to have it site wide.

Neat and easy. Hopefully useful to someone out there and I know there is room for improvement also.

Leave a Reply

You must be logged in to post a comment.