我有几个字符串可以是这种格式:
const s1 = "https://test1.com/testPage";
const s2 = "https://test2.com/testPage?specificParam=1"
const s3 = "https://test3.com/someOtherPage?specificParam=2&restParam=3";
因此,当我在函数中读取它时,我必须检查字符串是否包含查询参数,如果是,则我必须使用它进行编码
window.btoa()
到所有查询参数。如果不直接重定向。有人能帮忙做这件事吗?
function test(path){
const href = window.location.origin + path;
if(href.includes('?')){
// split all the query params and then attach `btoa` to it and then openthe url
with encoded params
}
window.open(href, '_blank', 'no-referer');
}