Set as the code of home page and favorite site, compatible with IE, chrome, firefox

web front end nineteen thousand nine hundred and ninety-four 11 years ago (2012-11-18)

I believe that many friends are looking for the codes of "set as home page" and "collect this site". Now there are many codes on the Internet, but the compatibility is not very good. Let's share these two codes with good compatibility, Tuoyuan Network Some of theme I hope it can save everyone's time. Why write when you can use it directly?

Javascript code:

 //Set as Home Page function SetHome(obj,url){ try{'url(#default#homepage)'; obj.setHomePage(url); }catch(e){ if(window.netscape){ try{"UniversalXPConnect"); }catch(e){ Alert ("Sorry, this operation was browser Reject! \N  n Please enter 'about: config' in the browser address bar and enter, then set [signed. applets. codebase_principal_support] to 'true' "); } }else{ Alert ("Sorry, the browser you are using cannot complete this operation.  n  nYou need to manually set ["+url+"] as the home page."); } } } //Collect this site function AddFavorite(title, url) { try { window.external.addFavorite(url, title); } catch (e) { try { window.sidebar.addPanel(title, url, ""); } catch (e) { Alert ("Sorry, the browser you are using cannot complete this operation.  n  nAdding a favorite failed, please use Ctrl+D to add it"); } } }

Html code:

 <a href="javascript: void (0);" onclick="SetHome (this, 'replace the domain name here');">Set as the home page</a> <a href="javascript: void (0);" onclick="AddFavorite ('Tuoyuan - an expert on customizing original websites around you! ', location. href)">Collect this site</a>

If applied to zblog In the theme, you need to improvise and replace the website URL and website name with the theme tag. The codes are as follows:

Html code:

 <a href="javascript: void (0)" onclick="SetHome (this, '<# ZC_BLOG_HOST #>');">Set as Home Page</a> <a href="javascript: void (0)" onclick="AddFavorite ('<# ZC_BLOG_NAME #>', location. href)">Collect this site</a>