Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript add update query parameter to url

function update_query_parameters(key, val) {
   uri = window.location.href
      .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
      .replace(/^([^?&]+)&/, "$1?");
   return uri;
}
// examples: the following may update ?page=4 in url and redirects to 
window.location.href = update_query_parameters('page', '4);
Source by zgadzaj.com #
 
PREVIOUS NEXT
Tagged: #javascript #add #update #query #parameter #url
ADD COMMENT
Topic
Name
2+3 =