1 <script language="javascript"> 2 //加入收藏 3 function AddFavorite(sURL, sTitle) 4 { 5 try 6 { 7 window.external.addFavorite(sURL, sTitle); 8 } 9 catch (e) 10 { 11 try 12 { 13 window.sidebar.addPanel(sTitle, sURL, ""); 14 } 15 catch (e) 16 { 17 alert("加入收藏失败,请使用Ctrl+D进行添加"); 18 } 19 } 20 } 21 22 //设为首页 23 function SetHome(obj,vrl){ 24 try{ 25 obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl); 26 } 27 catch(e){ 28 if(window.netscape) { 29 try { 30 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 31 } 32 catch (e) { 33 alert("此操作被浏览器拒绝! 请在浏览器地址栏输入“about:config”并回车 然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); 34 } 35 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 36 prefs.setCharPref('browser.startup.homepage',vrl); 37 } 38 } 39 } 40 </script> 41 42 使用方法: 43 <a href="#" onclick="SetHome(this,window.location)">设为首页</a> 44 <a href="#" onclick="AddFavorite(window.location,document.title)">收藏本站</a>