Copy Code code as follows:
<script>
function Goto_url (URL) {
var new_url = "Http://shop.usteel.com/index.php?app=list_release";
var d_date = getparameter ("date", url);
if (d_date!= ') {
New_url + = "&" +d_date;
}
var species = getparameter ("species", url);
If (species!= ') {
New_url + = "&" +species;
}
window.open (New_url);
}
JavaScript gets the specified parameter and its corresponding value
function getparameter (parastr, URL)
{
var result = "";
Get all parameter list data in a URL
var str = "&" + Url.split ("?") [1];
var paraname = parastr + "=";
Determines whether the parameter to be obtained exists
if (Str.indexof ("&" +paraname)!=-1)
{
If you want to get a parameter to the end that also contains "&"
if (str.substring str.indexof (paraname), str.length). IndexOf ("&")!=-1)
{
Get the argument to get to the end of the string
var tmpstr=str.substring (Str.indexof (paraname), str.length);
Intercepts the characters between the start of a parameter and the location of the nearest "&"
Result=tmpstr.substr (Tmpstr.indexof (Paraname), Tmpstr.indexof ("&")-tmpstr.indexof (Paraname));
}
Else
{
Result=str.substring (Str.indexof (paraname), str.length);
}
}
Else
{
Result= "";
}
Return (Result.replace ("&", ""));
}
</script>
The following example is a complete test
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>javascript get URL parameters and parameter values </title>
<script type= "Text/javascript" >
<!--
var url = "http://www.baidu.com/?age=25&k=1&site=asp&abc=123;"
JavaScript gets the specified parameter and its corresponding value
function getparameter (parastr, URL)
{
var result = "";
Get all parameter list data in a URL
var str = "&" + Url.split ("?") [1];
var paraname = parastr + "=";
Determines whether the parameter to be obtained exists
if (Str.indexof ("&" +paraname)!=-1)
{
If you want to get a parameter to the end that also contains "&"
if (str.substring str.indexof (paraname), str.length). IndexOf ("&")!=-1)
{
Get the argument to get to the end of the string
var tmpstr=str.substring (Str.indexof (paraname), str.length);
Intercepts the characters between the start of a parameter and the location of the nearest "&"
Result=tmpstr.substr (Tmpstr.indexof (Paraname), Tmpstr.indexof ("&")-tmpstr.indexof (Paraname));
}
Else
{
Result=str.substring (Str.indexof (paraname), str.length);
}
}
Else
{
result= "no such parameter";
}
Return (Result.replace ("&", ""));
}
Call method: var variable name = getparameter ("parameter name to get", url address)
var r = getparameter ("Age", url);
Test output, the result is: site=popasp
Alert (R);
Depending on the results obtained, you can use
var pname = r.split ("=") [0]; Gets the name of the parameter
var pvalue = r.split ("=") [1]; Get parameter values
Test output:
Alert ("Parameter name:" + pname + "\ n" + "parameter value:" + pvalue);
Other practical applications:
According to the need, with the following methods to achieve their own functions;
var hostname = Location.hostname; Get current domain name (does not contain http://)
var localurl = location.href; Get the current complete URL address information (including http://, domain name, path, specific file and all pass parameters)
var referurl = Document.referrer; Get the complete URL information on the previous page (including http://, domain name, path, specific file and all pass parameters)
-->
</script>
<body>
</body>