Answers for "add query params in url javascript"

0

add url query in js

const urlParams = new URLSearchParams(window.location.search);

urlParams.set('order', 'date');

window.location.search = urlParams;
Posted by: Guest on October-14-2021
0

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);
Posted by: Guest on October-29-2020

Code answers related to "add query params in url javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language