-
-
Save omidnasri/ec7cd32aed49608e7a71 to your computer and use it in GitHub Desktop.
Replacing query string parameter values.
This file contains 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
// Update the appropriate href query string parameter | |
function paramReplace(name, string, value) { | |
// Find the param with regex | |
// Grab the first character in the returned string (should be ? or &) | |
// Replace our href string with our new value, passing on the name and delimeter | |
var re = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
delimeter = re.exec(string)[0].charAt(0), | |
newString = string.replace(re, delimeter + name + "=" + value); | |
return newString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment