Article introduction of Wulin.com (www.vevb.com): Favorite website code that supports Firefox, IE6.ie7.ie8.ie9.
The following is the detailed code
<script>
var HomepageFavorite = {
//Set as homepage
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 (This operation is rejected by the browser. If you want to enable this function, please enter about:config in the address bar, and then enter the value of the item signed.applets.codebase_principal_support to 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);
}
}
,
// Add to favorites
Favorite: function Favorite(sURL, sTitle) {
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, );
}
catch (e) {
alert (If you fail to add to favorites, please add it manually.);
}
}
}
}
</script>
Support Firefox, IE6.ie7.ie8.ie9 to add to favorites/set as homepage code
<a href=javascript:HomepageFavorite.Homepage() _fcksavedurl=javascript:HomepageFavorite.Homepage() >Set as homepage</a>
<a href=javascript:HomepageFavorite.Favorite(window.location.href, document.title) _fcksavedurl=javascript:HomepageFavorite.Favorite(window.location.href, document.title) >Add to favorites</a>