您的位置:首页 > 其它

兼容IE和火狐设为首页和收藏的例子

2012-03-26 00:00 417 查看
top

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function addCookie()
{
if (document.all)
{
alert("我是ie");
window.external.addFavorite('http://www.hao123.com','疯狂音乐网');
}
else if (window.sidebar)
{
alert("我是火狐");
window.sidebar.addPanel('疯狂音乐网', 'http://www.hao123.com', "");
}
}
function setHomepage()
{
if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://www.baidu.com');

}
else if (window.sidebar)
{
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','http://www.baidu.com');
}
}

</script>
<title>top</title>

</head>

<body>
<ol>
<li><a href="javascript:;" onClick="addCookie()">加入收藏夹(IE、Firefox均可)</a></li>
<li><a href="javascript:;" onClick="setHomepage()">设置为首页(IE、Firefox均可)</a></li>
</ol>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息