
Code
<!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=gb2312" />
<title>bb家园,兼容 IE6,IE7,FF 的"加入收藏"及设为首页代码!</title>
</head>
<script type="text/javascript" language="javascript">
<!-- 加入收藏代码 Start -->

function AddFavorite(sURL, sTitle)
{

try
{
window.external.addFavorite(sURL, sTitle);

} catch (e)
{

try
{
window.sidebar.addPanel(sTitle, sURL, "");

} catch (e)
{
alert("加入收藏失败,请手动添加.");
}
}
}
<!-- 加入收藏代码 End -->
<!-- 设为首页代码 Start -->

function setHomepage(pageURL)
{

if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(pageURL);
}

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',pageURL);
}
}
<!-- 设为首页代码 End -->
</script>

<body>
<a href="javascript:setHomepage('http://www.bb2h.com');">设为首页</a>
<a href="#" onclick="javascript:AddFavorite('http://www.bb2h.com', 'bb家园|见证我们的爱情故事,我们曾经的诺言,我们彼此相爱的一生.');return false">加入收藏</a>
</body>
</html>


posted on
2009-10-12 11:23
飞鸟42
阅读(
294)
评论()
收藏
举报