Copy Code code as follows:
<title>javascript Settings Homepage and Favorites page (compatible with IE and Firefox) </title>
<script>
URLs: links to Favorites; Title: The name of the favorite item
function Addfavorite (url,title)
{
If the URL or title is empty, it defaults to the current page URL and title.
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: To set the link for the home page
function sethomepage (URL)
{
If the URL is empty, the current page URL is assumed to be the 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!") Please enter "About:config" in the browser address bar and return the value of [Signed.applets.codebase_principal_support] to ' true ' and double-click. ");
}
}
var prefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice ( Components.interfaces.nsIPrefBranch);
Prefs.setcharpref (' browser.startup.homepage ', url);
}
}
</script>
<body>
<a onclick= "sethomepage (' http://www.jb51.net/')" title= "Set as homepage" href= "javascript:" > Set as Homepage </a>
<a onclick= "Addfavorite (' http://www.jb51.net/', ' online Notes ')" title= "Favorites" href= "javascript:" > Favorites </a>
</body>