Set homepage and Favorites JavaScript code (ie,firefox,chrome compatible browser) _javascript tips

Source: Internet
Author: User

Because the Chrome,safari,opara browser does not support automatic "set as Home" & "Add Favorites".  So we can only try, catch a moment, give a wrong hint! It's perfect.

In other IE, many people have also encountered it window.external.addFavorite.  will be the problem of error. So I have to throw out the message.

Add to Favorites:

Copy Code code as follows:

function Addfavorite () {
if (document.all) {
try{
Window.external.addFavorite (Window.location.href,document.title);
}catch (e) {
Alert ("Join collection failed, please use Ctrl+d to add");
}

}else if (Window.sidebar) {
Window.sidebar.addPanel (Document.title, Window.location.href, "");
}else{
Alert ("Join collection failed, please use Ctrl+d to add");
}
}

Set as homepage:
Copy Code code as follows:

function setHomePage () {
if (document.all) {
Document.body.style.behavior= ' url (#default #homepage) ';
Document.body.setHomePage (WINDOW.LOCATION.HREF);
}else if (Window.sidebar) {
if (Window.netscape) {
try{
Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
}catch (e) {
Alert ("This action is rejected by the browser and if you want to enable it, enter About:config in the Address bar and then signed.applets.codebase_principal_support the value to true");
}
}
var prefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice (components. Interfaces.nsiprefbranch);
Prefs.setcharpref (' Browser.startup.homepage ', window.location.href);
}else{
Alert (' Your browser does not support automatic setting of the home page, please use the browser menu manually set! ');
}
}

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.