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:

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Bookmark this Page</title>

<scriptlanguage="javascript"type="text/javascript">

function addBookmark() {

bookmarkurl = document.URL;

bookmarktitle = document.title;

if (document.all) //Check the condition for IE

window.external.AddFavorite(bookmarkurl, bookmarktitle)

elseif (window.sidebar) // Check the condition for Mozilla

{

window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");

}

}

</script>

</head>

<body>

<formid="form1"runat="server">

<div>

<ahref="javascript:addBookmark();">Bookmark this page!</a>

</div>

</form>

</body>

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

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Bookmark this Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<ahref="javascript:if(document.all)window.external.AddFavorite(location.href,document.title);else%20if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');">Bookmark this Page!</a>