DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> HTML基礎知識 >> HTML和Xhtml >> 設為首頁和收藏網站代碼(火狐,IE6.ie7.ie8.ie9都管用)
設為首頁和收藏網站代碼(火狐,IE6.ie7.ie8.ie9都管用)
編輯:HTML和Xhtml     

以下為詳細代碼
<script>
var HomepageFavorite = {
//設為首頁
Homepage: function () {
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("該操作被浏覽器拒絕,如果想啟用該功能,請在地址欄內輸入 about:config,然後將項 signed.applets.codebase_principal_support 值該為true");
history.go(-1);
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', window.location.href);
}
}
,

//加入收藏
Favorite: function Favorite(sURL, sTitle) {
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e) {
alert("加入收藏失敗,請手動添加.");
}
}
}
}
</script>
支持火狐,IE6.ie7.ie8.ie9的加入收藏/設為首頁代碼
<a href="javascript:HomepageFavorite.Homepage()" _fcksavedurl="javascript:HomepageFavorite.Homepage()" >設為首頁</a>
<a href="javascript:HomepageFavorite.Favorite(window.location.href, document.title)" _fcksavedurl="javascript:HomepageFavorite.Favorite(window.location.href, document.title)" >加入收藏</a>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved