Copy the 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 parameters and their corresponding values
function getParameter(paraStr, url)
{
var result = "";
//Get all parameter list data in the URL
var str = "&" + url.split("?")[1];
var paraName = paraStr + "=";
//Determine whether the parameter to be obtained exists
if(str.indexOf("&"+paraName)!=-1)
{
//If the parameter to be obtained still contains "&" at the end
if(str.substring(str.indexOf(paraName),str.length).indexOf("&")!=-1)
{
//Get the parameters to be obtained to the end of the string
var TmpStr=str.substring(str.indexOf(paraName),str.length);
//Intercept the characters from the beginning of the parameter to the nearest "&" occurrence position
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 example below is complete and tested
Copy the code code as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Javascript gets 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 parameters and their corresponding values
function getParameter(paraStr, url)
{
var result = "";
//Get all parameter list data in the URL
var str = "&" + url.split("?")[1];
var paraName = paraStr + "=";
//Determine whether the parameter to be obtained exists
if(str.indexOf("&"+paraName)!=-1)
{
//If the parameter to be obtained still contains "&" at the end
if(str.substring(str.indexOf(paraName),str.length).indexOf("&")!=-1)
{
//Get the parameters to be obtained to the end of the string
var TmpStr=str.substring(str.indexOf(paraName),str.length);
//Intercept the characters from the beginning of the parameter to the nearest "&" occurrence position
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("&",""));
}
//Calling method: var variable name = getParameter("Parameter name to be obtained", URL address)
var r = getParameter("age",url);
//Test output, the result is: site=popasp
alert(r);
//Can be used based on the results obtained
var pName = r.split("=")[0]; //Get parameter name
var pValue = r.split("=")[1]; //Get parameter value
//Test output:
alert("Parameter name:" + pName + "/n/n" + "Parameter value: " + pValue);
//Other practical applications:
//You can use the following methods to achieve the functions you want to achieve as needed;
//var hostname = location.hostname; //Get the current domain name (excluding http://)
//var localurl = location.href; //Get the current complete URL address information (including http://, domain name, path, specific file and all passed parameters)
//var referurl = document.referrer; //Get the complete URL information of the previous page (including http://, domain name, path, specific file and all passed parameters)
//-->
</script>
</head>
<body>
</body>
</html>