Monday, April 12, 2010

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




Please visit my new Web Site https://coderstechzone.com



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:
Opera_Mozilla Firefox, Internet explorer IE

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 Favorites</a>

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

3 comments:

sirmus said...

it's all great but doesn't work with IE. it just goes to the home page when clicked. but it's ok with opera and firefox. what can be wrong?
and is there a way to make it work with google chrome too?

Anonymous said...

this is good it is working

Anonymous said...

Its a superrr article

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash