js修改window对象中的url历史记录

//页面地址:http://localhost/11/account.html
//访问页面后,地址变为:http://localhost/11/account.html?type=banana
console.log(window.location.search); // 空
window.history.pushState('','', window.location.href + '&type=banana');
console.log(window.location.search); //&type=banana

点击浏览器返回按钮,返回的页面地址是:http://localhost/11/account.html

通过这种方式,修改url参数,页面不会被重新加载,可用于分页加载。

原文地址:https://www.cnblogs.com/cqingt/p/5682150.html