前者的含義是:將當(dāng)前打開的頁面設(shè)置為瀏覽器的首頁,當(dāng)瀏覽器啟動(dòng)時(shí),自行打開該頁面!
后者的含義是:將當(dāng)前打開的頁面添加到收藏夾,將其網(wǎng)址保存起來,方便今后訪問,這極大的方便了很多網(wǎng)友,如果我們上網(wǎng)發(fā)現(xiàn)哪個(gè)網(wǎng)站比較好,想收藏起來,但是域名又難記,這個(gè)時(shí)候,將其添加到收藏夾,是最有效的方法了!收藏夾還可以建立文件夾,可以很方便的將收藏起來的網(wǎng)址分門別類歸類到不同的文件夾下!
如果你也有一個(gè)網(wǎng)站,你也想讓別人設(shè)置你的網(wǎng)站為首頁,讓更多的網(wǎng)友添加自己的網(wǎng)站到收藏夾,這種功能我們?nèi)绾文軐?shí)現(xiàn)呢?
下面提供代碼:
<html>
<head>
<title>hello,js
</title>
</head>
<script>
function rmousedown(){
if (event.button==2||event.button==3) window.external.addFavorite
('http://www.ybh888.com','ybh888');
}
</script>
<!--1.離開網(wǎng)頁時(shí)彈出-->
<!--2.網(wǎng)頁載入時(shí)彈出-->
<!--3.按下鼠標(biāo)彈出-->
<!--4.右鍵彈出-->
<body onunload="window.external.addFavorite('http://www.ybh888.com','ybh888');"
onload="window.external.addFavorite('http://www.ybh888.com','ybh888');" onmousedown="rmousedown();
">
<!--body標(biāo)簽的onmousedown替換為如下:
onMouseDown="new Function(window.external.addFavorite('http://www.ybh888.com','ybh888'));"-->
<!--幾種設(shè)為首頁的代碼-->
<!--鼠標(biāo)單擊時(shí)提示設(shè)為首頁1-->
<p align="center">
<a href="#" onClick="this.style.behavior='url (#default#homepage)';this.setHomePage
('http://www.ybh888.com');" target="_self" >設(shè)為首頁1</a><br>
<!--鼠標(biāo)單擊時(shí)提示設(shè)為首頁2兼容火狐和ie-->
<a href="javascript:setHomepage();" >設(shè)為首頁 2</a><br>
<script type="text/javascript">
function setHomepage()
{
if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(window.location.href);
}
else if (window.sidebar)
{
if(window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert( "該操作被瀏覽器拒絕,如果想啟用該功能,請(qǐng)?jiān)诘刂窓趦?nèi)輸入 about:config,然后將
項(xiàng) signed.applets.codebase_principal_support 值該為true" );
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService
(Components. interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',window.location.href);
}
}
</script>
<!--設(shè)為首頁3-->
<script language="javascript">
function myhomepage(){
this.homepage.style.behavior='url(#default#homepage)';this.homepage.sethomepage
('http://www.google.cn');
}
</script>
<a href=http://www.ybh888.com name="homepage"
onclick="myhomepage();">設(shè)為首頁3</a><br>
<!--鼠標(biāo)指向時(shí)提示設(shè)為首頁4-->
<!--加入收藏夾1兼容火狐和ie-->
<a href="javascript:addBookmark('http://www.ybh888.com','殷保華');">加入收藏1 </a><br>
<script type="text/javascript">
function addBookmark(url,title) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
}
else if(document.all) {
window.external.AddFavorite( url, title);
}
else if( window.opera && window.print ) {
return true;
}
}
</script>
<!--加入收藏夾2-->
<a target="_top" href="javascript:window.external.addFavorite('http://www.ybh888.com','ybh888');">加
入收藏2</a><br>
<!--鼠標(biāo)指向時(shí)出現(xiàn)alert窗口
<a href=# onMouseOver="alert('aaaa');">xxxx</a>-->
聯(lián)系客服