JavaScript获取URL中参数

function getQueryString(name) 
{
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return unescape(r[2]);
				}
				return null;
}

//获取URL中code参数
//http://xxx.xxx.com?code=123
var code = getQueryString('code');

//now code = 123

参考:
https://blog.csdn.net/qq_36947128/article/details/78594462
https://www.cnblogs.com/c9999/p/5852597.html
https://www.runoob.com/w3cnote/js-get-url-param.html

你可能感兴趣的:(前端,JavaScript)