First of all, the title of this post is a bit misleading. No JavaScript code or any code for that matter can claim to add a bookmark in all browsers.
What we can say though, is that the code we present has been tested to work in all major browsers except Google Chrome.
Bookmarks come in handy when it comes to building visitor loyalty and getting visitors to come back to your site. The JavaScript code snippet we show in this article creates a simple hyperlink which, when clicked, requests that the browser add the current page to its list of bookmarks.
You can simply copy the code below to generate your own Add to bookmarks link.
<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 now!</a>
The code above gives:
Placing the Javascript directly into the href attribute of the anchor tag makes the snippet more portable, self-contained and easy to set-up since no external JavaScript is needed for it to work.
We encourage you to test it in your current browser, and if it suits your needs, you can use something similar on your site. If the code does not work work for you, post a comment with your browser version information and we will try to help.
UPDATE (SEP. 3 2011): There is no way (which is immediately obvious) which allows you to add bookmarks via Javascript in Google Chrome.