zoukankan      html  css  js  c++  java
  • [转] 兼容IE和Firefox的设为首页和收藏的Javascript代码

             function  addCookie() {   //  加入收藏夹
                 if  (document.all) {
                    window.external.addFavorite(
    ' http://taotao.wsyren.com ' ' 牛吧 ' );
                }
                
    else   if  (window.sidebar) {
                window.sidebar.addPanel(
    ' 牛吧 ' ' http://taotao.wsyren.com ' "" );
                }
            }

            
    function  setHomepage() {   //  设置首页
                 if  (document.all) {
                    document.body.style.behavior 
    =   ' url(#default#homepage) ' ;
                    document.body.setHomePage(
    ' http://taotao.wsyren.com ' );

                }
                
    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://taotao.wsyren.com ' );
                }

            }

    摘录自:http://csprogrammer.blog.51cto.com/212533/51081

    调用方法:

         < href ="javascript:void(0)"  onclick ="setHomepage()" > 设为首页 </ a >  
        
    < href ="javascript:void(0)"  onclick ="addCookie()" > 加入收藏 </ a >
  • 相关阅读:
    解决Win8设置为快速启动后ubuntu不能访问win下磁盘的方法
    Why Not Specialize Function Templates?
    Build your first web service with PHP, JSON and MySql
    本地开发与linux服务器端的文件传输
    数据库设计中一对多的解决方法.
    C++ 模板练习摘要
    Understanding ASP.NET Validation Techniques
    我的sublime text 个人设置
    Eclipse 快捷键
    数字图像处理
  • 原文地址:https://www.cnblogs.com/peak/p/1444504.html
Copyright © 2011-2022 走看看