设为主页的js方法,兼容ie,firefox

一般在ie下面 

<a  href="#" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.reworlds.com')">设置为主页</a>

如果是firefox 则要自己写setHomePage()函数了(不推荐,一般谁也不去改这个设置,兼容ie就好)

要使用脚本在firefox下设置主页,首先必须确认在浏览器的“about:config”中,把
  signed.applets.codebase_principal_support
  设置成true

function setHomePage(a)
  {
  
   if (document.all)
   {
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage('http://www.reworlds.com');
   }
   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.reworlds.com');
   }
  }

原文地址:https://www.cnblogs.com/ytmf007/p/1640360.html