设为首页、加入收藏代码,兼容IE和fireFox

  1. <!--/设为首页 加入收藏 兼容Firefox IE-->
  2. <script language="javascript" type="text/javascript">
  3. function addCookie() {  // 加入收藏
  4.             if (document.all) {
  5.                 window.external.addFavorite('http://www.baidu.com', '百度');
  6.             }
  7.             else if (window.sidebar) {
  8.             window.sidebar.addPanel('百度','http://www.baidu.com', "");
  9.             }
  10.         }        function setHomepage() {  // 设为首页
  11.             if (document.all) {
  12.                 document.body.style.behavior = 'url(#default#homepage)';
  13.                 document.body.setHomePage('http://www.baidu.com');            }
  14.             else if (window.sidebar) {
  15.                 if (window.netscape) {
  16.                     try {
  17.                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  18.                     }
  19.                     catch (e) {
  20.                          alert("该操作被浏览器拒绝,假如想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
  21.                     }
  22.                 }
  23.                  var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  24.                 prefs.setCharPref('browser.startup.homepage','http://www.baidu.com');
  25.             }        }
  26. </script>
posted @ 2012-09-06 15:43  longailili  阅读(153)  评论(0)    收藏  举报