JavaScript gets the two methods of the current URL parameter:
Returns a string as a parameter, such as:class_id=3&id=2&
function geturlargstr() {
var q=location. Search. Substr(1);
var qs=q. Split(' & ');
var argstr=';
if(qs) {
For(var i=0; I<Qs. Length; I+ +) {
Argstr+=Qs[I].Substring (0,qs[ iindexof ( ' = ' ' = ' +qs[ isubstring (qs[iindexof ( ' = ' ) +< Span class= "lit" >1) + ' & ' ;
}
}
return argstr;
}
Returns the parameter as an object form
function geturlargobject() {
var args=new Object();
var query=location. Search. Substring(1); Get query string
< Span class= "pun" >< Span class= "pun" > var pairs= query.//disconnects at comma
For (var i=0; I<pairs. Length; I+ +) {
var pos=pairs[i]. IndexOf(' = '); Find Name=value
< Span class= "pun" >< span class= "str" > if (pos ==-1) {// Skip if not found;
continue;
}
var argname=pairs[i]. Substring(0,pos); Extract name
var value=pairs[i]. Substring(pos+1); Extract value
args[argname]=unescape(value); Save As Property
}
return args; Return object
}
Also list some JavaScript to get a functional approach to each part of the URL:
- Window. Location. Host; //Returns the host part of the URL, for example: www.xxx.com
- Window. Location. hostname; //Return to www.xxx.com
- Window. Location. href; //Returns the entire URL string (in the browser is the full address bar), for example : www.xxx.com/index.php?class_id=3&id=2
- Window. Location. Pathname; //Return to/a/index.php or /index.php
- Window. Location. Protocol; //Returns the protocol part of the URL, for example: Http:,ftp:,maito: And so on.
- Window. Location. the port portion of Ports//url, if the default 80 port is used, then the return value is not the default of 80 but the null character
JS gets each parameter of the URL.