“Favorite” Link — How To Create a Bookmark Link

By  on  

I get a lot of requests from customers to add a link to their website that allows the user to "bookmark" their site. I generally try to get them to drop that idea. The functionality of an "add to favorites" link isn't cross-browser compatible -- neither Firefox or Opera will allow it. Internet Explorer does allow favorite links and most of the internet still uses IE, so I do have a script to accomplish this goal.

The Code

/*  BOOKMARK THE PAGE  */
function bookmark()
{
	if ((navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(window.location,document.title);
	}
	else
	{
		alert('Don\'t forget to bookmark us! (CTRL-D)');
	}
}

The Explanation

It's a pretty simple JavaScript function. The function first checks to see if the user is browsing using Internet Explorer. If so, the function makes the appropriate call to IE, providing the page URL and title. If the user doesn't use Internet Explorer, short instructions are provided to prompt the user's browser to to add the current page as a favorite.

Recent Features

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Create a Sexy Persistent Header with Opacity Using MooTools or jQuery

    I've been working with the Magento eCommerce solution a lot lately and I've taken a liking to a technique they use with the top bar within their administrative control panel. When the user scrolls below a specified threshold, the top bar becomes attached to the...

  • By
    Facebook-Style Modal Box Using MooTools

    In my oh-so-humble opinion, Facebook's Modal box is the best modal box around. It's lightweight, subtle, and very stylish. I've taken Facebook's imagery and CSS and combined it with MooTools' awesome functionality to duplicate the effect. The Imagery Facebook uses a funky sprite for their modal...

Discussion

  1. Nice post. Are you calling the bookmark function when the page loads? It seems like it since the else statement is an alert box. Perhaps a better way is by calling the function onclick of a link. Like you, I wouldn’t personally want to add this, but I think targeting specific browsers and using the addons that each browser offers is a good thing if you can provide a better experience without affecting the other visitors.

  2. No Jeremy, the function isn’t run when the page loads. You would simply call this function from a link.

    Calling this implicitly for all users would be website suicide.

  3. a

    why only work for IE when no one uses that?

  4. Bangladesh varsity information and admit

  5. Samrat

    Nice post. I saw a similar script on another website and was wondering why it didn’t work on my Firefox.

  6. Thanks to the iPad and similar devices, this will become obsolete.

  7. Is this functional on all browser? I think i should try the code myself. Thanks for sharing. But if you got an idea already, please tell me or send me the right script for cross browser for bookmark us script. Thanks.

  8. Thank you so much, I’ll be putting your code at my sites. I already tried it and it works like a charm. Your the best admin. Home you can modify it on firefox so that the popup bookmark will be the same result as I.E. Thanks. I appreciate your help!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!