Add to Bookmarks Javascript Code

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.

Click here to bookmark this page! 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%20if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');">Bookmark this page</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.

This should work on pretty much all major browsers. Using javascript: in href instead of in an actual javascript function is just to make the bookmark code easier for the layman to handle. In most cases this sort of functionality will only go in one location on a page so making things overly complicated for most sites probably won't do.

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

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):