Search This Blog

Tuesday, January 4, 2011

Add to Favorites (IE) / Bookmark (Mozilla Firefox, Opera) Page Javascript

Developers basically use shortcut command to add a page into favorite list or bookmark list but most of the users does not know how they can add an important page into their favorite list or bookmark list. Thats why if developer add a bookmark link or add to favorite link on important pages so that users can easily bookmark the page. Here in this article i will explain how one can add favorites link or bookmark link in a page using cross browser javascript code. My example will work on Internet explorer, Opera and Mozilla Firefox like below:

To implement my example code first add a aspxa page into your project then under HTML head tag add the below javascript method to bookmark or add to favorites:


<script type="text/javascript">
    function Add_Bookmark_Favorite(url, title)
    {
        if (window.sidebar)
        { // Mozilla Firefox Bookmark
            //Make sure "Load this bookmark in the sidebar is deselected
            window.sidebar.addPanel(title, url, "");
            return false;
        }
        else if (window.external)
        { // IE Favorites
            window.external.AddFavorite(url, title);
            return false;
        }
        else if (window.opera && window.print)
        { // Opera Bookmark
            return !addToFav(url, title)
        }
    }
script>



Now add the below link into your asp.net aspx page like below:


<a href="" title="" rel="sidebar" onclick="return Add_Bookmark_Favorite(location.href, document.title);">Bookmark / Add to Favoritesa>

Bookmark / Add to Favorites

Now run the page and click on the "Bookmark / Add to Favorites" link will popup a window to bookmark this page.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.