Jquery location.reload()不带参数
我有下面的代码Jquery location.reload()不带参数,jquery,Jquery,我有下面的代码 <button id="RefreshMe">Refresh Page</button> <script> jQuery('#PageRefresh').click(function() { location.reload(); }); </script> 刷新页面 jQuery(“#页面刷新”)。单击(函数(){ location.reload(); }); 这很好,但是我的页面在表单中有一些隐藏值,因此它没有重新加载
<button id="RefreshMe">Refresh Page</button>
<script>
jQuery('#PageRefresh').click(function() {
location.reload();
});
</script>
刷新页面
jQuery(“#页面刷新”)。单击(函数(){
location.reload();
});
这很好,但是我的页面在表单中有一些隐藏值,因此它没有重新加载www.example.com,而是重新加载www.example.com?a=111等,这会导致错误,因为uri太大。我希望用户返回www.example.com而不是www.example.com?a=111还需要添加什么?更好的答案是:
document.location = document.location.replace(/[\?].*/,'');
history.pushState({}, 'title', '/');
这将刷新没有参数和路径的页面(基本上是您的主页)。但假设您有一个非主页,例如:
yoursite.com/pricing?myparam=shazam
如果只想删除参数,可以执行以下操作:
history.pushState({}, 'title', '/pricing');
你最终会得到这样的结果:
yoursite.com/pricing