zoukankan      html  css  js  c++  java
  • 设为首页,及添加收藏

    设为首页,以及添加收藏夹代码,随处可见,找到网站,查看源代码即可,一般都是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',"");

  • 相关阅读:
    从‘void*’到‘int’的转换损失精度
    ../lib//libscsdblog.so: undefined reference to `pthread_atfork'
    使用Crypto++库的CBC模式实现加密
    VIM常用命令
    mysql bin-log三种模式
    windows64位Oracle安装和PL/SQL配置
    Maven项目中突然找不到Build Path或maven dependencies library
    org.springframework.beans.factory.config.MethodInvokingFactoryBean的使用
    使用Spring的StingUtils的commaDelimitedListToStringArray来获取字符串数组
    Spring注入
  • 原文地址:https://www.cnblogs.com/9421/p/1638841.html
Copyright © 2011-2022 走看看