JavaScript设置首页和收藏页面(兼容IE和火狐) <script> <BR> //url:要收藏的链接;title:收藏项的名称 <BR> function AddFavorite(url,title) <BR> { <BR> //如果url或者title为空,默认为当前页面url和title。 <BR> if(!(url&&title)) <BR> { <BR> url=document.URL; <BR> title=document.title; <BR> } <br><br> if (document.all)//IE <BR> { <BR> window.external.addFavorite(url,title); <BR> } <BR> else if (window.sidebar)//火狐 <BR> { <BR> window.sidebar.addPanel(title, url, ""); <BR> } <BR> } <br><br> //url:要设置为首页的链接 <BR> function SetHomepage(url) <BR> { <BR> //如果url为空,默认为当前页面url。 <BR> if(!url) <BR> { <BR> url=document.URL; <BR> } <br><br> if (document.all)//IE <BR> { <BR> document.body.style.behavior = 'url(#default#homepage)'; <BR> document.body.setHomePage(url); <BR> } <BR> else if (window.sidebar)//火狐 <BR> { <BR> if (window.netscape) <BR> { <BR> try <BR> { <BR> window.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); <BR> } <BR> catch (e) <BR> { <BR> alert("此操作被浏览器拒绝!请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); <BR> } <BR> } <BR> var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); <BR> prefs.setCharPref('browser.startup.homepage', url); <BR> } <BR> } <BR> </script>
设为首页 收藏