1 <html> 2 <head> 3 <title>test</title> 4 <script type="text/javascript"> 5 function AddFavorite(sURL, sTitle) 6 { 7 try 8 { 9 window.external.addFavorite(""+sURL+"",""+sTitle+""); 10 11 } 12 catch (e) 13 { 14 try 15 { 16 if(window.sidebar) 17 { 18 window.sidebar.addPanel(""+sTitle+"", ""+sURL+"", ""); 19 }else{ 20 alert("加入收藏失败,该浏览器不支持自动加入收藏功能,请使用Ctrl+D进行添加。"); 21 } 22 } 23 catch (e) 24 { 25 alert("加入收藏失败,该浏览器不支持自动加入收藏功能,请使用Ctrl+D进行添加。"); 26 } 27 } 28 } 29 function SetHome(obj,vrl){ 30 try{ 31 obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl); 32 } 33 catch(e){ 34 if(window.netscape) { 35 try { 36 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 37 } 38 catch (e) { 39 alert("此操作被浏览器拒绝!请在浏览器地址栏输入“about:config”并回车/n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); 40 } 41 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 42 prefs.setCharPref('browser.startup.homepage',vrl); 43 }else{ 44 alert("设为主页失败,该浏览器不支持自动设为主页功能。请手动添加"); 45 } 46 } 47 } 48 </head> 49 <body> 50 <span onclick="SetHome(this,window.location);" style="cursor:pointer;" mce_style="cursor:pointer;">设为主页</span> <font color="#FFFFFF" size="2" >|</font> <span onclick="AddFavorite(window.location,document.title);" style="cursor:pointer;" mce_style="cursor:pointer;">加入收藏</span> 51 </body> 52 </html>