Skip to content

Instantly share code, notes, and snippets.

@thermistor
Last active September 14, 2016 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thermistor/ec76c10168c03e84c102eee62bc7d10a to your computer and use it in GitHub Desktop.
Save thermistor/ec76c10168c03e84c102eee62bc7d10a to your computer and use it in GitHub Desktop.
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