First method:, code comparison professional recommendation
Copy Code code as follows:
<script>
function Getlocationparam (param) {
var request = {
Querystring:function (val) {
var uri = Window.location.search;
var re = new RegExp ("+val+" = ([^&?] *) "," IG ");
Return (Uri.match (re))? ( decodeURI (Uri.match (re) [0].substr (val.length+1)): "];
}
}
Return request. QueryString (param);
}
var uid=getlocationparam ("UID");
</script>
The second method:
Of course, we can get the value of the parameters in the background, and then in the foreground JS code to get the value of the variable, the specific way to refer to my article: JavaScript to get the background C # variables and invoke the background method.
In fact, we can also directly in JS to get the value of the requested parameter, by using Window.location.search can get to the current URL of the start of the string, such as the previous link to obtain the search for the id=001. The obtained string is then processed so that the value of the parameter can be obtained.
Copy Code code as follows:
function Geturlparam (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = window.location.search.substr (1). Match (REG);
if (R!= null)
Return unescape (r[2]);
return null;
}
When you call the above method, you can get the value of the parameter you want, as long as you pass in the name of the parameter, such as Geturlparam ("id").