Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn to set it as the homepage and add it to the favorites js
Function addFavorite (){
If (document. all ){
Try {
Window. external. addFavorite (window. location. href, document. title );
} Catch (e ){
Alert ("failed to add to favorites, please add with Ctrl + D ");
}
} Else if (window. sidebar ){
Window. sidebar. addPanel (document. title, window. location. href ,"");
} Else {
Alert ("failed to add to favorites, please add with Ctrl + D ");
}
}
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 ("this operation is rejected by the browser. If you want to enable this function, enter about: config in the address bar, and set the value of signed. applets. codebase_principal_support to true ");
}
}
Var prefs = Components. classes ['@ mozilla.org/preferences-service%1'}.getservice (Components. interfaces. nsIPrefBranch );
Prefs. setCharPref ('browser. startup. homepage', window. location. href );
} Else {
Alert ('your browser does not support automatic homepage settings. Please use the browser menu to manually set it! ');
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB