//url例子 http://xxx.com/xx/xxx?id=0001&code=123123&childUrl=/bbb/ccc/fff/?id=34445&save=true
function parseURLParams(url) {
const str = url.slice(url.indexOf('?')+1)
const paramList = str.split('&');
var result = {};
paramList.forEach((paramStr) => {
const strList = paramStr.split('=');
var name = strList[0] || '';
var value = strList[1] || '';
if (result.hasOwnProperty(name)) {
if (Array.isArray(result[name])) {
result[name].push(value);
} else {
var temp = result[name];
result[name] = [temp, value]
}
} else {
result[name] = value
}
});
return result;
}
// encodeURIComponent编码
var str = `http://xxx.com/xx/xxx?id=0001&code=123123&childUrl=${encodeURIComponent('/pages/addreceipt/mainland/mainland?familyId=1237983478&sourceInSave=true')}`
// 获取所有参数
console.log(parseURLParams(str))
// decodeURIComponent解码
console.log(decodeURIComponent(parseURLParams(str).childUrl))
【JavaScript】若url中的参数childUrl依然是一个url,如何获取到完整的childUrl内容
于 2022-07-27 22:53:22 首次发布