JavaScript One of the ways to get URL parameters
- 2021-08-05 08:47:16
- OfStack
If the address bar URL is: abc. html? m = tomms & c=allsearchlist & pageNo=1 & pageNum=20 & text=1
<script>
//JavaScript Get url , and put url The method that changes the parameters in the, arr The value of the array is the value of each parameter
var url = window.document.location.href.toString();
var u = url.split("?");
var arr = [];
if(typeof(u[1]) == "string"){
u = u[1].split("&");
for(var i in u){
var a = (u[i].split("="));
arr[a[0]] = a[1];
}
}
</script>
Note: When URL has Chinese, the Chinese parameters will be garbled!