RSS
Facebook
Twitter

Thursday 3 January 2013


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:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Bookmark this Page</title>
<script language="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)
else if (window.sidebar) // Check the condition for Mozilla
{
window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Bookmark this Page</title>
</head>
<body>
<form id="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>
</div>
</form>
</body>
</html>

0 comments:

Post a Comment