Set Home page by JavaScript (IE/FF)

In Internet Explorer, we can set the current page as clients' home page by the following code easily:


<a class="chlnk" style="cursor:hand;font-weight:bold;color:#004080;font-family:Verdana" HREF onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.java-scripts.net');">Click here to make Java-scripts.net your default homepage!</a>

However, it is not work under the Firefox circumstances

To use Script set the Firefox's home page, first of all, we need make sure the browser settings allow us to do that:

1.Type" about:config" to the Firefox's address bar, and press enter;
2.Find the key which names :signed.applets.codebase_principal_support
3.Set its value to true

Then, we can use the following script to achieve the facing goal:

<script language="javascript">
function setHomepage()
{
if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://www.asp.net/130.aspx');
}

else if (window.sidebar)
{
if(window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}

catch(e)
{
alert("this action was aviod by your browser,if you want to enable,please 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.asp.net/130.aspx');
}

}

</script>
<input type="button" value="set home page" onclick="setHomepage();" />

0 comments