js设置首页

function SetHome(url) {
    var err_msg = "设置失败!,在浏览器地址栏中输入 about:config 然后将 signed.applets.codebase_principal_support 设置为true";
    try{
      if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(url);
      } else if (window.sidebar) {
        if (window.netscape) {
          try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
          } catch (e) {
            alert(err_msg);
            history.go(-1);
          }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', window.location.href);
      }
    }catch(e){
      alert('设置失败!');
    }
  }

你可能感兴趣的:(js设置首页)