Javascript Essentials Part 1

Add to Favorites Cross Browser Script

Add the following In Head Section
<script type="text/javascript">
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")

Now that you have included script in head section, lets move to body part of script.

Add the following In Body Section

You can display add to favorite link in web page based on text or image as following.

Text Based
<a href="javascript:bookmarksite('Webstylepress', '')">Bookmark this site!</a>
Image Based
<a href="#" onClick="javascript:window.external.AddFavorite('', 'Webstylepress, Web developers guide');"><img src="images/bt2_1.jpg" alt=".add to favourites" name="Image4" width="34" height="34" border="0"></a>
Onload Add to favorites Script

This script will be added in body tag of web page. When web page will be completed loading, it will ask user to add website into favorites.

<body onLoad="if(document.all) window.external.AddFavorite(window.document.location,window.document.title)">