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)