"Add to Favorites" code of IE6 and IE7:
Window. external. addFavorite (sURL, sTitle );
Note:
The first letter a of addFavorite is not capital! Even if Microsoft uses uppercase letters for reference, it is "better than words ".
Add to favorites code in Firefox:
Method 1,
<A href = "http://www.bkjia.com" title = "YCPENG's blog" rel = "sidebar"> Add to favorites </a>
The key lies in rel = "sidebar"; the href attribute value is used as the favorite URL; and the title is used as the favorite name.
Method 2,
Window. sidebar. addPanel (sTitle, sURL ,"");
The first parameter is the favorite name, the second parameter is the favorite URL, and the third parameter is the URL required for custom Tab, which is a string of zero length. Note that the parameter order is different from addFavorite. We recommend the second method.
No matter which method, after adding to favorites, you can click the favorites item to open the webpage in the sidebar. There are only two ways to open the webpage in the main window: Right-click to open the webpage; method 2: Right-click to modify its attributes. This is a pity for Firefox favorites.
Full code compatible with "add to Favorites" of IE6, IE7, and FF:
<Script type = "text/javascript" language = "javascript">
Function AddFavorite (sURL, sTitle ){
Try {
Window. external. addFavorite (sURL, sTitle );
} Catch (e ){
Try {
Window. sidebar. addPanel (sTitle, sURL ,"");
} Catch (e ){
Alert ("failed to add to favorites, please manually add .");
}
}
}
Function setHomepage (pageURL ){
If (document. all ){
Document. body. style. behavior = 'url (# default # homepage )';
Document. body. setHomePage (pageURL );
}
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', pageURL );
}
}
</Script>
<A href = "javascript: setHomepage ('url');"> set as homepage </a>
<A href = "#" onclick = "javascript: AddFavorite ('url', 'sitename'); return false"> Add to favorites </a>
From shunzi Network