AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Web Development - Javascript - Add to favorites

Add to favorites



One thing that you want visitors to do when they come to your site is to add it to their favorites/bookmarks. I know there are toolbar icons that the visitor can use but it doesn't hurt just to remind them while viewing your pages. Internet explorer has created an object that can activate the favorites dialog box from a link. So all we have to do is detect IE and dynamically write the link. If IE is not detected we dynamically produce bookmark reminder text.

This script is especially useful if your site uses frames or server side includes or both.

If you get errors when using this script - make sure that your page title (SSI version) or your description (static version) does not contain single or double quotes.

add to favorites link - example 1

This first example is for use on a static site and needs to be added to all the pages you want to be bookmarkable. Cut and paste the following code, changing URL to the full url of the page being bookmarked. Change DESC to the link text you want displayed in the favorites list.

<script>
<!--
if (document.all && document.getElementById){
document.write("<a href=\"#\" onclick=\"window.external.AddFavorite('http://URL ', ' DESC ');return false;\">bookmark</a>")
}
else
{
document.write("bookmark this page")
}
// -->
</script>



add to favorites link - example 2

Another variation is for use on a site that is built using server side includes(SSI). If you are using SSI properly, you will probably have a footer document that is included on every page. Cut and paste the following code into your footer document to add the link to your entire site.

<script>
<!--
if (document.all && document.getElementById){
document.write("<a href=\"#\" onclick=\"window.external.AddFavorite('" +document.URL+ "', '" +document.title+ "');return false;\">bookmark</a>")
}
else
{
document.write("bookmark this page")
}
// -->
</script>







Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]