Home > Scripts > Add To Favorites

Home    |    Candybar    DollMakers    RoomMakers    |    Roiworld    BBDI    Star Dolls    |    Puzzles    Smilies    Links   

Back to Scripts

Tutorial, How to "Add to Favorites" in HTML

Creating a simple 'add to favorites' link.

This is essentially a client side request, that asks the browser to 'add to favorites'. Each browser may respond differently to this request, IE will pop open a window asking the user if they wish to add to their favorites.
<a style="cursor:hand" onClick="window.external.addfavorite('http://elouai.com/bookmark-favorites.php', 'Add to Favorites Tutorial');"> <img width=16 height=16 border=0 src='images/star.gif'> <u> Add to Favorites</u>...</a> The "add to favorites" html script outputs:
Add to Favorites...

There are 4 parts to the script:
  • style="cursor:hand" - changes the cursor to be a hand when over this html link.
  • onclick="window.external.addfavorite('http://elouai.com/smiley_face.php','Add to Favorites Tutorial');" - on the mouse click call the window addfavorite, saving this url "http://elouai.com/bookmark-favorites.php" and title "eLouai set HomePage and add to Favorites Tutorials" setting the home page to http://elouai.com/bookmark-favorites.php.
  • <img width=16 height=16 border=0 src="images/star.gif"> - We set the image to a recognizable icon, one used by IE since 96% of the web uses IE. Border 0 to hide the border.
  • Add to Favorites... - The text to display in the html link.

To dynamically generate the page that you are wish to add to favorites we can use a bit of PHP. This way we can cut and paste the script and apply it to any page without having to rewrite the script.

..window.external.addfavorite('<?php echo $_SERVER['DOCUMENT_ROOT'];?>')..

The output:
Add to Favorites...

MSDN: AddFavorite Method

comments powered by Disqus

Creative Commons License All work by eLouai is licensed under a Creative Commons Attribution 3.0 Unported License
contact: elouai@gmail.com        ©2003-2019 eLouai.com, All rights reserved        Hosting by Web Hosting Canada        Privacy Policy        About