Answers for "js append get parameter"

2

javascript set query parameter

function updateQueryStringParameter(uri, key, value) {
  var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
  var separator = uri.indexOf('?') !== -1 ? "&" : "?";
  if (uri.match(re)) {
    return uri.replace(re, '$1' + key + "=" + value + '$2');
  }
  else {
    return uri + separator + key + "=" + value;
  }
}
//You can reload the url like so
 var newUrl=updateQueryStringParameter(window.location.href,"some_param","replaceValue");
 window.history.pushState("", "Page Title Here", newUrl);
Posted by: Guest on July-17-2019
0

js add query param

function setParam(uri, key, val) {
    return uri
        .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
        .replace(/^([^?&]+)&/, "$1?");
}
Posted by: Guest on November-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language