To obtain the passed values of HTML static page parameters, you can use the split function to cut into arrays by parameters and use regular expressions to obtain them. The specific implementation is as follows
Example 1Use regular expressions to obtain Get
var LocString = String(window.document.location.href); function getQueryStr(str) { var rs = new RegExp("(^|)" + str + "=([^&]*)(&|$)", "gi").exec(LocString), tmp; if (tmp = rs) { return tmp[2]; } // parameter cannot be found return ""; }
Call method
document.getElementById("user").value = getQueryStr("user"); document.getElementById("password").value = getQueryStr("password"); document.getElementById("sysno").value = getQueryStr("sysno");
Example 2Use the split function to cut into arrays according to parameters
But be sure to remember that this method is only for files containing The URL of the parameter is useful. If the other party uses the POST method to pass the parameter, the URL will not contain the parameter, so this technique is only useful for the GET method or the URL with specified parameters.
Look at a complete example below
aa.htm is the parameter input and penetration interface
bb.htm is the parameter receiving and processing interface
aa.htm
bb.htm
The above is the detailed content of Detailed example of how Javascript uses functions and regular expressions to obtain static page parameter values. For more information, please follow other related articles on the PHP Chinese website!