“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
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

  • By
    5 Awesome New Mozilla Technologies You’ve Never Heard Of

    My trip to Mozilla Summit 2013 was incredible.  I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out.  MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

Incredible Demos

  • By
    Dijit’s TabContainer Layout:  Easy Tabbed Content

    One of Dojo's major advantages over other JavaScript toolkits is its Dijit library.  Dijit is a UI framework comprised of JavaScript widget classes, CSS files, and HTML templates.  One very useful layout class is the TabContainer.  TabContainer allows you to quickly create a tabbed content...

  • By
    MooTools FontChecker Plugin

    There's a very interesting piece of code on Google Code called FontAvailable which does a jQuery-based JavaScript check on a string to check whether or not your system has a specific font based upon its output width. I've ported this functionality to MooTools. The MooTools...

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!