<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="content-type"content="text/html;charset=gb2312"/>
<title>设为首页与添加收藏夹代码【兼容多浏览器】</title>
<scriptlanguage="javascript">
functionaddBookmark(title,url){
if(window.sidebar){
window.sidebar.addPanel(title,url,"");
}elseif(document.all){
window.external.AddFavorite(url,title);
}elseif(window.opera&&window.print){
returntrue;
}
}
functionsetHome(url)
{
if(document.all){
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(url);
}elseif(window.sidebar){
if(window.netscape){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入about:config,然后将项signed.applets.codebase_principal_support值该为true");
}
}
if(window.confirm("你确定要设置"+url+"为首页吗?")==1){
varprefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',url);
}
}
}
</script>
</head>
<body>
<ahref="javascript:void(null)"onClick="setHome('https://www.yc58.com');">设为首页</a>-<ahref="javascript:addBookmark('壹家怡园','https://www.yc58.com')">加入收藏</a>
</body>
</html>
|