Answers for "replace query param from js"

1

js update query string

var searchParams = new URLSearchParams(window.location.search);
searchParams.set("foo", "bar");
window.location.search = searchParams.toString();
Posted by: Guest on October-28-2020
0

how to change the query parameter of the url in javascript

// Construct URLSearchParams object instance from current URL querystring.
var queryParams = new URLSearchParams(window.location.search);
 
// Set new or modify existing parameter value. 
queryParams.set("myParam", "myValue");
 
// Replace current querystring with the new one.
history.replaceState(null, null, "?"+queryParams.toString());

// OR do a push to history
tory.pushState(null, null, "?"+queryParams.toString());
Posted by: Guest on December-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language