Created
December 30, 2022 16:52
-
-
Save benergize/5d6c36544482d11aa533273ef130e576 to your computer and use it in GitHub Desktop.
Function to change/add GET variables in a URL string
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 urlBuilder(param,val,url=window.location.href) { | |
return url.indexOf(param+"=") != -1 ? String(url).replace(new RegExp(param + "=[^&]+","ig"),param+"="+val) : url + "&" + param + "=" + val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment