Add Bookmark link to website using javascript | Add to Favorites (IE) / Bookmark (Firefox) using Javascript


Introduction

Here I will explain how to add bookmark link to our website using JavaScript in asp.net.

Description

In many websites we will see link like “Bookmark this Site” if we click on that bookmark link that will prompts the user with dialog box to add that specified link in favorites list. If we want to add that type functionality to our website we can write in different ways. Here I will explain in two different ways to add Bookmark functionality

First Method:
   1:  
   2: <html xmlns="http://www.w3.org/1999/xhtml">
   3: <head runat="server">
   4: <title>Bookmark this Page</title>
   5: <script language="javascript" type="text/javascript">
   6: functionaddBookmark() {
   7: bookmarkurl = document.URL;
   8: bookmarktitle = document.title;
   9: if(document.all)//Check the condition for IE
  10: window.external.AddFavorite(bookmarkurl, bookmarktitle)
  11: else if(window.sidebar)// Check the condition for Mozilla
  12: {
  13: window.sidebar.addPanel(bookmarktitle, bookmarkurl,"");
  14: }
  15: }
  16: </script>
  17: </head>
  18: <body>
  19: <form id="form1" runat="server">
  20: <div>
  21: <a href="javascript:addBookmark();">Bookmark this page!</a>
  22: </div>
  23: </form>
  24: </body>
  25: </html>
After add above code run your application and check your output it will work for you
Second Method

Now add following code in your aspx page and check it 1:  
   2: <html xmlns="http://www.w3.org/1999/xhtml">
   3: <head runat="server">
   4: <title>Bookmark this Page</title>
   5: </head>
   6: <body>
   7: <form id="form1" runat="server">
   8: <div>
   9: <ahref="javascript:if(document.all)window.external.AddFavorite(location.href,document.title);else%20if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');">Bookmark 
  10: this Page!</a>
  11: </div>
  12: </form>
  13: </body>
  14: </html>