I want to dynamically change a specific parameter in the navigation bar.
I have this url and want to change "pedro" by "max":
http://mywebsite.com/?par1=mynameis&par2=pedro&par3=nicetomeetyou
By using this, it removes all my parameters.
hello = "max"
window.history.replaceState(null, null, "?par2="+hello);
This is what I want:
http://mywebsite.com/?par1=mynameis&par2=max&par3=nicetomeetyou
and not
http://mywebsite.com/?par1=mynameis&par2=max
3
Answers
Use the URL interface
I prefer to start from the full URL but you can use the URLSearchParams instead
This may not be ideal, but it works.
You can use
URLSearchParams
: