JavaScript Settings Home and Favorites Page Small example _javascript tips

Source: Internet
Author: User
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>

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.