<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///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 = "/?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 = "&" + ("?")[1];
var paraName = paraStr + "=";
//Judge whether the parameters to be obtained exist
if(("&"+paraName)!=-1)
{
//If the parameter to be retrieved still contains "&" at the end?
if(((paraName),).indexOf("&")!=-1)
{
//Get the string to obtain the parameter to be obtained to the end
var TmpStr=((paraName),);
//Intercept the characters from the beginning of the parameter to the nearest "&" occurrence position
result=((paraName),("&")-(paraName));
}
else
{
result=((paraName),);
}
}
else
{
result="No such parameter";
}
return (("&",""));
}
//Call method: var variable name = getParameter("parameter to be obtained", URL address)
var r = getParameter("age",url);
//Test output, the result is: site=popasp
alert(r);
//You can use it according to the results obtained
var pName = ("=")[0]; //Get parameter name
var pValue = ("=")[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 implement the functions you want to implement as needed;
//var hostname = ; //Get the current domain name (not including http://)
//var localurl = ; //Get the current complete URL address information (including http://, domain name, path, specific file and all passed parameters)
//var referurl = ; //Get the complete URL information of the previous page (including http://, domain name, path, specific files and all passed parameters)
//-->
</script>
</head>
<body>
</body>
</html>