Skip to content

Instantly share code, notes, and snippets.

@benergize
Created December 30, 2022 16:52
Show Gist options
  • Save benergize/5d6c36544482d11aa533273ef130e576 to your computer and use it in GitHub Desktop.
Save benergize/5d6c36544482d11aa533273ef130e576 to your computer and use it in GitHub Desktop.
Function to change/add GET variables in a URL string
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