Copyright of xueying studio. For more information, see [http://blog.csdn.net/lina791211]
1. Preface
Set the homepage in pure Javascript and add it to favorites.
2. Set the homepage
// Set it to the home page function SetHome (obj, vrl) {try {obj. style. behavior = 'url (# default # homepage) '; obj. setHomePage (vrl);} catch (e) {if (window. netscape) {try {netscape. security. privilegeManager. enablePrivilege ("UniversalXPConnect");} catch (e) {alert ("this operation was rejected by the browser! \ N enter "about: config" in the address bar of the browser, press enter \ n, set the value of [signed. applets. codebase_principal_support] To 'true', and double-click it. ");} Var prefs = Components. classes ['@ mozilla.org/preferences-service%1'%.getservice (Components. interfaces. nsIPrefBranch); prefs. setCharPref ('browser. startup. homepage ', vrl);} else {alert ("your browser does not support it. Follow these steps: 1. open the browser settings. 2. Click set webpage. 3. Enter "+ vrl +" and click "OK. ");}}}
3. Add to favorites
// Add to favorites compatible with 360 and IE6function shoucang (sTitle, sURL) {try {window. external. addFavorite (sURL, sTitle);} catch (e) {try {window. sidebar. addPanel (sTitle, sURL, "") ;}catch (e) {alert ("failed to add to favorites, please add with Ctrl + D ");}}}
4. Obtain URL parameters
Function getUrlParam (name) {var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $ )"); // construct a regular expression object var r = window containing the target parameter. location. search. substr (1 ). match (reg); // match the target parameter if (r! = Null) return unescape (r [2]); return null; // return parameter value}
5. Solve Chinese garbled characters
// Send the post page $ ('# simpleSearchButton '). click (function () {var _ k = $ ('# textfield '). val (); var url = ''; if (_ k = null | _ k = "") {// url = encodeURI ('<% = path %>/'); return;} else {url = encodeURI ('<% = path %>/search. jsp? Keyword = '+ _ k);} url = encodeURI (url); // <span style = "font-family: Arial; "> encryption twice (encode twice when one encode may fail) </span> window. open (url, '_ self ');});
// Accept parameter page // use the method window provided in section 4. onload = function () {var keyword = getUrlParam ('keyword'); // obtain keyif (keyword = null) keyword = ''; keyword = decodeURI (keyword); // decrypt twice (if one encode fails, encode is used twice, so decode is required twice) $ ("# textfield "). val (keyword); simpleQuery (); $ ("# search_paging "). show ();}