Recently developed projects need to use JavaScript to read the values of parameters in the Url string.
By finding information and experimenting, I finally succeeded
The script is as follows:
The code copy is as follows:
<script type="text/javascript">
function GetRequest(strName)
{
var strHref = window.location.href; //Get the Url string
var intPos = strHref.indexOf("?"); // parameter start position
var strRight = strHref.substr(intPos + 1);
var arrTmp = strRight.split("&"); // Parameter splitter
for(var i = 0; i < arrTmp.length; i++)
{
var arrTemp = arrTmp[i].split("=");
if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
}
return "";
}
</script>
test:
The code copy is as follows:
<script>
var id=GetRequest("ID");
alert(id);
</script>
If you have other methods, please tell me, this article will be updated continuously
Welcome to communicate and learn together~