1.获取地址栏参数
方法一:
const url = 'https://sls.console.aliyun.com/next/project/test-hz-hbb/logsearch/amber-hsinga?spm=5176.2020520112.108.d7.794b34c0Ocwl5o&hiddenBack=true';
function getUrlParams(url, hiddenBack) {
let oUrl = new URL(url);
return oUrl.searchParams.get(hiddenBack);
}
getUrlParams(url,'hiddenBack'); // "true"
方法二:
const url = 'https://sls.console.aliyun.com/next/project/test-hz-hbb/logsearch/amber-hsinga?spm=5176.2020520112.108.d7.794b34c0Ocwl5o&hiddenBack=true';
function getURLParams(url){
let q={}
url.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v)
return q
}
getURLParams(url)
//{spm: "5176.2020520112.108.d7.794b34c0Ocwl5o", hiddenBack: "true"}
网友评论