设为首页&加入收藏

刚刚学习JavaScript今在网上见着了这俩功能,也学着写了一下。 在下面这东东浏览器的不同写有着许多不同的差异,这点让人头痛。。。
<script type="text/javascript">
         function fAddFavorite(TL,UL)
         {
            if(document.all)
               window.external.AddFavorite(TL,UL);
            else
               window.sidebar.addPanel( UL,TL,"");
         
         }
        
         function SetHome(obj,vrl)
    {
        try
        {
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        }
                        catch (e) {
                                alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
    }
       </script>

<a href=# onClick="SetHome(this,window.location);return false;">设为首页</a></li>
<a  href="javascript:fAddFavorite(window.location,'Xue~~  新闻收集工作站')">加入收藏</a>

你可能感兴趣的:(JavaScript,浏览器,Security)