把頁面設置為首頁,加入收藏功能,支持ie,ff,chrome,safari,360安全,qq,遨遊,搜狗瀏覽器,不兼容360急速瀏覽器的兼容模式下加入收藏功能:
代碼如下:
<html>
<head>
<title>把頁面設置為首頁,加入收藏功能,支持ie,ff,chrome,safari,360安全,qq,遨遊,搜狗瀏覽器,不兼容360急速瀏覽器的加入收藏功能</title>
</head>
<body>
<div>?<a?href="">首頁</a>?|?<a?onclick="SetHome(window.location)"?href="javascript:void(0)">設為首頁</a>?|?<a?onclick="AddFavorite(window.location,document.title)"?href="javascript:void(0)">加入收藏</a>?</div>
<script?type="text/javascript"?language="javascript">
//加入收藏
function?AddFavorite(sURL,?sTitle)?{
sURL?=?encodeURI(sURL);?
try{
window.external.addFavorite(sURL,?sTitle);
}catch(e)?{
try{
window.sidebar.addPanel(sTitle,?sURL,?"");
}catch?(e)?{
alert("加入收藏失敗,請使用Ctrl+D進行添加,或手動在瀏覽器裏進行設置.");
}
}
}
//設為首頁
function?SetHome(url){
if?(document.all)?{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(url);
}else{
alert("您好,您的瀏覽器不支持自動設置頁面為首頁功能,請您手動在瀏覽器裏設置該頁面為首頁!");
}
}
</script>
</body>
</html>