[Code Collection] Set homepage and favorite JavaScript code (multi-browser compatible)

Source: Internet
Author: User

In fact, a lot of non-ie kernel browser is still not support through the code to set the page as the home page and add to the collection function, so it is compatible, in fact, is only a try,catch after the reminder.  Add to Favorites:/* * author:2010-12-27 11:33:02 Teresa * Discription:add favorite * Function Addfavorite () {if (document.all) {try {Window.external.addFavorite (window.location.href, document.title);} catch (E) {alert ("Failed to bookmark, use Ctrl+d to add");}} else if (Window.sidebar) {Window.sidebar.addPanel (Document.title, Window.location.href, "");} else {alert ("Add to collection failed, please use ctrl+d for adding");}} Homepage:/* * author:2010-12-27 11:33:02 Teresa * Discription:set Homepage * * Function sethomepage () {if (document.all) {doc ument.body.style.behavior = ' url (#default #homepage) ';d ocument.body.setHomePage (window.location.href);} else if (Window.sidebar) {if (Window.netscape) {try {Netscape.security.PrivilegeManager.enablePrivilege (" Universalxpconnect ");} catch (E) {alert ("The action is rejected by the browser, if you want to enable the feature, 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);p refs.setcharpref (' Browser.startup.homepage ', window.location.href);} else {alert (' Your browser does not support automatic setting of the homepage automatically, please manually set it using the browser menu! ');}}

  

[Code Collection] Set homepage and favorite JavaScript code (multi-browser compatible)

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.