最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - replaceState with empty string: Javascript - Stack Overflow

programmeradmin2浏览0评论

I've got this url:

website/con?blog=true

What I do in javascript is:

if (getURLparams(blog)) {
   RandomFunction();
   // change the url
   window.history.replaceState({}, '?blog=true', "blog=false");
}

However, I do not want to use blog=false, in fact I want empty string there. I tried ""/'' but they didn't work. Any idea or alternative? Thanks

I've got this url:

website.com/con?blog=true

What I do in javascript is:

if (getURLparams(blog)) {
   RandomFunction();
   // change the url
   window.history.replaceState({}, '?blog=true', "blog=false");
}

However, I do not want to use blog=false, in fact I want empty string there. I tried ""/'' but they didn't work. Any idea or alternative? Thanks

Share Improve this question asked Oct 18, 2017 at 8:37 popeyepopeye 5011 gold badge4 silver badges17 bronze badges 2
  • 1 The third parameter in replaceState is optional so you can not set it at all – Krusader Commented Oct 18, 2017 at 8:46
  • Tried. Didn't work. I want ?blog=true gone completely – popeye Commented Oct 18, 2017 at 8:55
Add a comment  | 

3 Answers 3

Reset to default 20

You can set it to location.pathname:

window.history.replaceState({}, '', location.pathname);

This will remove the URL params.

You can use a relative path:

window.history.replaceState({}, '', './');

You can try.. Emptying the last parameter of function replaceState. Like this.

window.history.replaceState({}, '?blog=true', "");

or

window.history.replaceState({}, '?blog=true');
发布评论

评论列表(0)

  1. 暂无评论