function getUrlParam(name){ var reg = new RegExp(‘(^|&)‘ + name + ‘=([^&]*)(&|$)‘); var result = window.location.search.substr(1).match(reg); return result ? decodeURIComponent(result[2]) : null;}
Where Window.location.search is the method to get the link parameter, previously used window.location.href and then split using the Split method. Just found Window.location.search.substr (1) seems more convenient.
The substr () method extracts a specified number of characters from the start subscript in a string, and substr (1) represents the intercept number, which gets the content after. Match () is then used to retrieve the matching of the regular expression.
where the regular var reg = new RegExp (' (^|&) ' + name + ' = ([^&]*) (&|$) '); "(^|&)" This matches the beginning or the & character, the overall expression looks for &+url parameter name = value +& format,& can not exist. This result is the content of the retrieved match, and then return to determine whether it is empty, if not empty result[2] here to represent the value of the parameter, that is, return the parameter value, if empty, return null.
function to get the value of a parameter on a URL link