Last active
March 27, 2019 10:07
-
-
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.
This file contains hidden or 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
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