Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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());
Source by zgadzaj.com #
 
PREVIOUS NEXT
Tagged: #change #query #parameter #url #javascript
ADD COMMENT
Topic
Name
5+2 =