Java code & lt; html & gt; & lt; head & gt; & lt; title & gt; JavaScript: Set the homepage and favorites page (compatible with IE and Firefox) & lt; /title & gt; & lt; script & gt; // url: Link to favorites; title: name of the favorites item functionAddFavorite (url, title) {// if u
Java code
JavaScript settings homepage and favorites page (compatible with IE and Firefox)
Script
// Url: the link to be added to favorites; title: The name of the added item
Function AddFavorite (url, title)
{
// If the url or title is empty, the current page url and title are used by default.
If (! (Url & title ))
{
Url = document. URL;
Title = document. title;
}
If (document. all) // IE
{
Window. external. addFavorite (url, title );
}
Else if (window. sidebar) // Firefox
{
Window. sidebar. addPanel (title, url ,"");
}
}
// Url: the link to be set as the homepage
Function SetHomepage (url)
{
// If the url is empty, the current page url is used by default.
If (! Url)
{
Url = document. URL;
}
If (document. all) // IE
{
Document. body. style. behavior = 'url (# default # homepage )';
Document. body. setHomePage (url );
}
Else if (window. sidebar) // Firefox
{
If (window. netscape)
{
Try
{
Window. netscape. security. PrivilegeManager. enablePrivilege ("UniversalXPConnect ");
}
Catch (e)
{
Alert ("this operation is rejected by the browser! Enter "about: config" in the address bar of your browser, press enter, set the value of [signed. applets. codebase_principal_support] To 'true', and double-click it. ");
}
}
Var prefs = Components. classes ['@ mozilla.org/preferences-service%1'}.getservice (Components. interfaces. nsIPrefBranch );
Prefs. setCharPref ('browser. startup. homepage', url );
}
}
Script
Set as Homepage
Favorites