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
3 Answers
Reset to default 20You 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');
replaceState
is optional so you can not set it at all – Krusader Commented Oct 18, 2017 at 8:46?blog=true
gone completely – popeye Commented Oct 18, 2017 at 8:55