Skip to content

Instantly share code, notes, and snippets.

@thermistor thermistor/set_param.js
Last active Sep 14, 2016

Embed
What would you like to do?
Set/update a query param via javascript function
// from https://gist.github.com/stinoga/8101816#gistcomment-1842990
function setParam(uri, key, val) {
return uri
.replace(new RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
.replace(/^([^?&]+)&/, "$1?");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.