Wednesday, May 18, 2011

How to add website in favorites list using ASP.NET and JavaScript


There are couple of ways to add website URL in browser Favorites list,
Just a have a look at below code snippet,

First method,
 <asp:Button ID="btnAddToFavorites" runat="server" Text="Add Me To Favorites List" OnClientClick="window.external.AddFavorite(location.href, document.title);" />

Second method,
 <html>

<head>

<script language="javascript">

function AddToFav()

{

bookmarkurl= "http://asheej.blogspot.com/";

bookmarktitle="Good .NET Articles"

if (document.all)

window.external.AddFavorite(bookmarkurl,bookmarktitle)

else if (window.sidebar) // firefox

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

}

</script>

</head>

<body>

<input TYPE="button" VALUE="Add to Favorites" onClick='javascript:AddToFav()' />

</body>

</html> 

No comments: