I’m wondering how I can add a new parameter to an existing url.
The problem is: the url may also contain an anchor.
For example:
http://www.example.com?foo=bar#hashme
And I want to add another parameter to it, so it results in this:
http://www.example.com?foo=bar&x=y#hashme
I used parts of The Awesome One‘s solution, and a solution found on this question:
Adding a parameter to the URL with JavaScript
Combining them into this script:
Example:
addParameter('http://www.example.com?foo=bar#hashme', 'bla', 'valuebla', false)Results in
http://www.example.com?foo=bar&bla=valuebla#hashme