1

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

Simon
  • 22,637
  • 36
  • 92
  • 121
  • 6
    I'd would really be pissed if some script would change my starting page. So terribly pissed you can't even imagine. – jAndy Nov 08 '10 at 12:55
  • http://stackoverflow.com/questions/946189/how-can-i-set-default-homepage-in-ff-and-chrome-via-javascript – Haim Evgi Nov 08 '10 at 12:56
  • Not sure why all of these questions on SO and other places get people so upset. The average user can't figure out how to set their homepage themselves, not easily, so why shouldn't a website be able to offer an easy button for the user if they want? OF COURSE THE BROWSER NEEDS TO CONFIRM THE ACTION WITH THE USER BEFORE ALLOWING IT. With 1 confirmation prompt in the browser, no reason they can't and shouldn't support this. Just like alert() they can have a "stop asking" option to avoid an endless loop. – eselk Jan 11 '13 at 18:06

2 Answers2

8

There isn't a cross-browser JavaScript way to do this...hopefully for obvious reasons. setHomePage() was removed as well, for the same reasons.

Think of if this way: if this were possible, your homepage would be an advertisement, I guarantee it.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
4

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.

Arild
  • 694
  • 6
  • 18
Pascal Qyy
  • 4,442
  • 4
  • 31
  • 46