Skip to content

Instantly share code, notes, and snippets.

@debonx
Last active March 27, 2019 10:07
Show Gist options
  • Save debonx/ed0496dfb7a83df85e50d2480659a506 to your computer and use it in GitHub Desktop.
Save debonx/ed0496dfb7a83df85e50d2480659a506 to your computer and use it in GitHub Desktop.
JQuery / Javascript small function to set URL parameters, for example https://your-link?param=value.
function setUrlParam(key,value) {
if (history.pushState) {
var params = new URLSearchParams(window.location.search);
params.set(key, value);
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + params.toString();
window.history.pushState({path:newUrl},'',newUrl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment