Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
Set/update a query param via javascript function
// from
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.