[英]window.location.replace() - not working as desired
我目前的 url 是:
http://localhost:3001/company/accountingvoucher/1755926b-023c-4944-8200-3402abfeb3d4/yes
我想在页面刷新时将最后一个查询参数从“是”更改为“否”。 我正在使用以下代码:
window.onload = () => {
let href = window.location.href;
if (href.match(/yes$/)) {
href = href.split("yes")[0] + "no";
window.location.replace(href);
}
}
问题是,我需要刷新页面两次才能使用“no”参数重新加载。 第一次刷新时,参数继续为“是”。
也许:
//var url = 'http://localhost:3001/company/accountingvoucher/1755926b-023c-4944-8200-3402abfeb3d4/yes'
var url = window.location.href;
var isYes = (url.substring(url.length - 3) == 'yes');
if (isYes){
url = url.replace('/yes', '/no');
window.location.href = url;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.