WebDevelopersNotes logo

home-icon Home / JavaScript / Creating Add to Favorites link and script in JavaScript

Creating Add to Favorites link and script in JavaScript

Creating Add to Favorites link and script in JavaScript

On this page we shall learn how to create an “Add to Favourites” link for your web site.

Let us first see the advantages of adding such a link:
If visitors really like your site, they can easily add it to their favorites list through the normal process – Under Internet Explorer, click on the “Favorites” menu item and then on “Add to Favorites…”.
However, they might just forget about this or they just might feel lazy (…you now what I mean). If you have an “Add To Favorites” link, you not only remind the visitors of the favorites folder but also prompt them to add your site and this just takes one click.

Here we use a little JavaScript and tie it up to the HREF tag of the link and here is the JavaScript function code:

function addfav()
   if (document.all)

Note: The javascript statement “window.external.AddFavorite(…” should be a single line

The part in red color in the above code is the URL and the blue is the Name you want to give to the link.

The function can be placed inside the document head or an external .js file and will be called from the link as:

<a href="javascript:addfav()">Add To Favorites</a>

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Sponsored Links


How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]


For a period of 10 days, IP addresses belonging to the offices within the US House of Representatives were banned from Wikipedia. This was done to restrain the modifications being made to the biographical articles of politicians by their staff on the online free encyclopaedia. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy