Syom Syom - 7 months ago 30
Javascript Question

are there any alternative to setHomePage function?

I need to set the home page in browser, but setHomePage works only in IE.

Are there any method to do it? (i can't find such results)

Thanks much

Answer

Personnaly, I found that with Google:

How do you set home page through java script for mozilla firefox?

Hi thuypv

Based on my experience, we cannot set the home page of Firefox, if the browser set signed.applets.codebase_principal_support to false, the only thing we can do is remind use to change the setting. You can try the following code, both for IE and Firefox:

<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();" />

If I’ve misunderstood your problem, please feel free to let me know.

Thanks.