JS get URL passing Parameters
Here is a javascript client solution for obtaining URL parameters with questring, equivalent to ASP's request. querystring, PHP's $ _ Get
Function:
<Script language = "JavaScript"> function getrequest () {var url = location. Search; // get URL "? "Var therequest = new object (); If (URL. indexof ("? ")! =-1) {var STR = URL. substr (1); STRs = Str. split ("&"); For (VAR I = 0; I <STRs. length; I ++) {therequest [STRs [I]. split ("=") [0] = (STRs [I]. split ("=") [1]) ;}return therequest ;}</SCRIPT>
Then, we can call this function to obtain the corresponding parameter values:
<Script language = "JavaScript">
VaR request = new object ();
Request = getrequest ();
VaR parameter 1, parameter 2, parameter 3, parameter n;
Parameter 1 = request [''parameter 1 ''];
Parameter 2 = request [''parameter 2''];
Parameter 3 = request [''parameter 3 ''];
Parameter n = request [''parameter n''];
</SCRIPT>
Obtain the parameter with the same name in the URL string.
Ii. Regular Expression Analysis.
Function getquerystring (name ){
VaR Reg = new
Regexp ("(^ | &)" + name +
"= ([^ &] *) (& | $)", "I ");
VaR r =
Window. Location. Search. substr (1). Match (REG );
If (R! = NULL) Return
(R [2]); return NULL;
}
Alert (getquerystring ("parameter name 1 "));
Alert (getquerystring ("parameter name 2 "));
Alert (getquerystring ("parameter name 3 "));
Other parameters:
// Set or obtain the specified file name or path of the object.
Alert (window. Location. pathname );
// Set or obtain the whole URL
Is a string.
Alert (window. Location. href );
// Set or obtain the URL
The associated port number.
Alert (window. Location. Port );
// Set or obtain a URL
.
Alert (window. Location. Protocol );
// Set or obtain href
Segment after the # In the attribute.
Alert (window. Location. Hash );
// Set or obtain the location or URL
Hostname and port number.
Alert (window. Location. HOST );
// Set or obtain href
The attribute following the question mark.
Alert (window. Location. Search );