Skip to content
Discussion options

You must be logged in to vote

Use the URL interface

const hello = 'max';
// let url = new URL(location.href); // from location.href
let url = new URL(`http://mywebsite.com/?par1=mynameis&par2=pedro&par3=nicetomeetyou`); // from string
url.searchParams.set('par2',hello); // change ONE parameter
console.log(url.searchParams.toString());
window.history.replaceState(null, null, `?${url.searchParams.toString()}`);

Replies: 1 comment

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issues Repository issues let you track features, problems, and more alongside your code Question Ask and answer questions about GitHub features and usage
2 participants