Created
October 24, 2016 18:02
-
-
Save zach-taylor/da1ff57d6178907100a77701445bdc5a to your computer and use it in GitHub Desktop.
function to add or update a query parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var updateQueryParam = function(query_param, new_value) { | |
var re = new RegExp('(' + query_param + '=)[^\\&]*'); | |
if (re.test(location.href)) { | |
location.href = location.href.replace(re, '$1' + new_value); | |
} else { | |
location.href = location.href + '?' + query_param + '=' + new_value; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment