I got a URL like this:
http://google.de/test.php?a=b&c=d&e=f
I know got to modify just one of the GET params like this: (c
is "h" instead of "d")
http://google.de/test.php?a=b&c=h&e=f
and redirect to the new url. All other GET params should stay the same.
How am I going to do this?
Replace location.search by your new arguments like "?foo=bar&tic=tac"
I agree its best to use a library for this purpose as mentioned in other answers.
However, here is a string replacement solution based on regular expressions if you need a simpler quick fix.
Here I'm replacing the query string key 'z' with 'newVlaue'
Have a look at this fiddle: http://jsfiddle.net/BuddhiP/PkNsx
Set or Update a URL/QueryString Parameter, and update URL using HTML history.replaceState()
You can try something like this:
Since your parameter can be at any place. So this will work fine
I've put together a really simple method but it will only work with what you're trying to achieve:
A little known feature of PHP is that a latter naming of an existing parameter overrides the earlier.
With this knowledge at hand, you can just do the following:
Easy.