Since chrome, safari, and opara browsers do not yet support automatic "set as homepage" & "add to favorites". So we can only try, catch, and give an error message! It's perfect.
In addition, in IE, many people have also encountered the problem that window.external.addFavorite. will report an error. So I had to throw a prompt message.
Add to favorites:
function addFavorite(){
if (document.all){
try{
window.external.addFavorite(window.location.href,document.title);
} catch(e){
alert( "Failed to add to favorites, please use Ctrl D to add" ); addPanel(document.title, window.location.href, "");
}else{
}else{
} alert( "Failed to add to favorites, please use Ctrl D to add" );
}
}
Set as homepage:
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 feature, please enter about:config in the address bar, and then sign the item. The value of applets.codebase_principal_support should be true" );
;
prefs.setCharPref('browser.startup.homepage',window.location.href);
}else{
alert('Your browser does not support automatic setting of homepage, please use your browser Menu manual settings!');
}
}