Small Example of setting the homepage and favorite pages in JavaScript _ javascript tips-js tutorial

Source: Internet
Author: User
This article introduces a small example of setting up the homepage and adding to favorites in JavaScript. For more information, see The Code is as follows:




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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.