手机登录/注册
X
登录
http://localhost:8080/?tracking_id=abc&convert_id=12
function GetQueryString(name) {
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
return null;
}
调用方法:
let tracking_id = GetQueryString("tracking_id"));
//获取url中"?"符后的字串,主动获取
function GetUrlParameter() {
const url = location.search;
let theRequest = new Object();
if (url.indexOf('?') != -1) {
let str = url.substr(1);
strs = str.split('&');
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
}
}
return theRequest;
}
调用方法:
let UrlParameter = new Object();
UrlParameter = GetUrlParameter();
var.tracking_id = UrlParameter.tracking_id;
var.convert_id = UrlParameter.convert_id;
function getQueryVariable(url, variable) {
const urlFormat = new URL(url);
//去掉?号
const query = urlFormat.search.substring(1);
const vars = query.split('&');
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split('=');
if (pair[0] === variable) {
return pair[1];
}
}
return false;
}