Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to set default home page in IE and Mozilla using JavaScript in asp.net

Dec 1, 2011
Introduction

Here I will explain how to set default home page in browser using JavaScript in asp.net.

Description

In many major websites we will see link like “Set as a home page” if we click on that home page link that will automatically change our browser default home page url to their particular page url. In IE browser we can easily set home page just by simple code but Mozilla we don’t have a chance to set home directly because of security concerns. If we want to set the home page in Mozilla first we need to set signed.applets.codebase_principal_support to true then run the below code to set home page initially that is in false mode. 

To enable this property in Mozilla follow below steps

1.      1) First open Mozilla browser and type about:config in address bar and click enter

2.      2) Now it will show some warning message click ok and now search for signed.applets.codebase_principal_support right click on it and select Toggle now Value will change to true

3) Once that property set then run the below code and click on set as home page button it will automatically will set your url as the home page.  

Write the below code in your page to set home page in your IE and Mozilla browsers 

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Add BookMark it Link to your website using JavaScript</title>
<script language="javascript" type="text/javascript">
function setHomepage() {
//Condition to set home page in IE
if (document.all) {
document.body.style.behavior = 'url(#default#homepage)';
document.body.setHomePage('http://www.aspdotnet-suresh.com');
}
//Condition to set home page in Mozilla
else if (window.sidebar) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("this action was aviod by your browserif you want to enableplease enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', 'http://www.aspdotnet-suresh.com');
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="set home page" onclick="setHomepage();" />
</form>
</body>
</html>
After add above code run your application and check your output it will work for you

Demo


 

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Abhinavsingh993 said...

Great Article Sir, Your always great and will be great, Thank you for this article
Your Biggest Fan on the earth,
Abhinav Kumar Singh

Darpan Samani said...

Hi suresh nice article but internet explorer show me one popup to confirm to set home page i want to remove that popup and directly set home page without popup??? it is possible

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.