js:设为首页

 

代码
        <script language="javascript">
        
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(
"抱歉!您的浏览器不支持直接设为首页。请在浏览器地址栏输入“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',vrl);
                }
            }
        }
    
</script>

 

  调用:

  <a href="#" onclick="javascript: SetHome(this, window.location);">设为首页</a>

posted @ 2010-02-25 08:51  弹着钢琴设计  阅读(206)  评论(0编辑  收藏  举报