Skip to main content

Add to Favorites (IE) / Bookmark (Firefox) Javascript

Most web browsers like Firefox (Ctrl+D), Opera (Ctrl+T) and IE (Ctrl+D) provide keyboard shortcuts to enable users bookmark their favorite pages.

But not every visitor is a power user, so for them, you can add a quick "Bookmark this page" link in all your pages. Clicking on the link prompts the user with a dialog box to add the specified URL to the Favorites list.

The javascript code mentioned on IE MSDN page doesn't work in other browsers.
window.external.AddFavorite(location.href, document.title);

The following modified version of "Add to Favorites" javascript code works across IE, Mozilla Firefox and Opera Browsers. Template Tags for Blogger, Movable Type and Wordpress platform are commented.
<script language="JavaScript1.2" type="text/javascript">
function CreateBookmarkLink() {

title = "Webpage Title";
// Blogger - Replace with <$BlogItemTitle$>
// MovableType - Replace with <$MTEntryTitle$>

url = "Webpage URL";
// Blogger - Replace with <$BlogItemPermalinkURL$>
// MovableType - Replace with <$MTEntryPermalink$>
// WordPress - <?php bloginfo('url'); ?>

if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) { // Opera Hotlist
return true; }

if (window.external) {
document.write('<a href =
"javascript:CreateBookmarkLink()");">Add to Favorites</a>');
} else if (window.sidebar) {
document.write('<a href =
"javascript:CreateBookmarkLink()");">Bookmark Page</a>');
} else if (window.opera && window.print) {
document.write('<a href =
"javascript:CreateBookmarkLink()");">Add Bookmark</a>');
If your audience are visiting the site from a different web browser or if javascript is not supported , the bookmark link is not displayed.