• 设为首页,及添加收藏


    设为首页,以及添加收藏夹代码,随处可见,找到网站,查看源代码即可,一般都是js实现..

    代码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        
    <title>9421 test</title>
    </head>
    <body>

    <script type="text/javascript">
       
    function setHomepage(){//设置首页 
       if(document.all){
          document.body.style.behavior
    ='url(#default#homepage)';
          document.body.setHomePage(
    'http://www.9421.org');
       }
       
       
    else if(window.sidebar){
            
    if(window.netscape){
                 
    try{
                     netscape.security.PrivilegeManager.enablePrivilege(
    "UniversalXPConnect");
                 }
                 
    catch(e){
                     alert(
    "您的浏览器未启用[设为首页]功能,开启方法:先在地址栏内输入about:config,然后将项 signed.applets.codebase_principal_support 值该为true即可");
                 }
            }
            
    var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref(
    'browser.startup.homepage','http://www.9421.org');
            alert(
    "设置完成!");
       } 
    }

    function addCookie(){//加入收藏夹 
    if(document.all){
           window.external.addFavorite(
    'http://www.56beijing.org''9421Test');
    }
    else if(window.sidebar){
          window.sidebar.addPanel(
    '9421Test','http://www.9421.org',"");
    }
    }
      
    </script> 
     
    <A  onclick="javascript:setHomepage();" href="#">设置首页 | </a> 
    <A  href="#" onclick="javascript:addCookie();"> 加入收藏夹 </a>
       
    </body>
    </html>

    关键代码:

     document.body.setHomePage('http://www.9421.org');

    /// var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
    ///prefs.setCharPref('browser.startup.homepage','http://www.9421.org');

     window.external.addFavorite('http://www.56beijing.org', '9421Test');

    /// window.sidebar.addPanel('9421Test','http://www.9421.org',"");

     判断浏览器:

    if(document.all){
           window.external.addFavorite('http://www.56beijing.org', '9421Test');
    }
    else if(window.sidebar){
          window.sidebar.addPanel('9421Test','http://www.9421.org',"");

  • 相关阅读:
    针式PKM软件进入华军分类下载月排名前6名
    读取xml
    一个简单的记事本程序
    python输出重定向
    重看ATL布幔之下的秘密
    nginx学习(二)动态加载各模块
    ngx_queue的理解
    nginx学习(三)IOCP的使用
    nginx学习(一)内存
    使用python实现一个通用协议测试工具
  • 原文地址:https://www.cnblogs.com/9421/p/1638841.html
Copyright © 2020-2023  润新知