an url like this:http://www.example.com/1.html?para1=ddd¶2=ccc
use js to get the values..
how to????
who can use js get url's parameter
Javascript does not have native access for GET parameter, so here is the other way how to obtain GET parameter
usage:
Code: Select all
<script language="JavaScript" type="text/javascript">
function getParam(strParamName)
{
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 )
{
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
{
if (aQueryString[iParam].indexOf("=") > -1 )
{
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}
</script>
Code: Select all
getParam('parameter')