var newurl = updateQueryStringParameter(window.location.href, 'sp', '2');
//向当前url添加参数,没有历史记录
window.history.replaceState({
	path: newurl
}, '', newurl);

function updateQueryStringParameter(uri, key, value) {
	if(!value) {
		return uri;
	}
	var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
	var separator = uri.indexOf('?') !== -1 ? "&" : "?";
	if (uri.match(re)) {
		return uri.replace(re, '$1' + key + "=" + value + '$2');
	}
	else {
		return uri + separator + key + "=" + value;
	}
}

 JS-使用history的replaceState方法向当前url追加参数

 replaceState不会有历史记录

 pushState 有历史记录

 

原文链接:https://blog.csdn.net/wang704987562/article/details/84631740

相关文章:

  • 2022-02-10
  • 2022-12-23
  • 2022-02-26
  • 2021-06-19
  • 2021-08-10
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-01-27
  • 2021-06-26
  • 2021-08-01
  • 2021-08-19
  • 2021-09-20
相关资源
相似解决方案