Advertisement
jargon

URL Stuff

Jul 5th, 2024
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Parse the current query string
  2. const url = new URL(window.location.href);
  3. const params = new URLSearchParams(url.search);
  4.  
  5. // Modify the query parameters (example: adding/updating a parameter)
  6. params.set('key', 'value'); // Replace 'key' and 'value' with your desired key-value pair
  7.  
  8. // Write the modified query string back to the URL
  9. url.search = params.toString();
  10. window.history.replaceState({}, '', url);
  11.  
  12. // Now the URL in the browser's address bar is updated with the new query string
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement