Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

javascript - history.pushState() change query values

If I have a link that is being changed with the function history.pushState({}, "", link); where my link is for example page.php?value=1&value2=2 Is there a way to just change the value2 with pushState() function instead of changing the whole link?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If what you're trying to do is change the URL without adding an additional entry to the history object, you might try replaceState.

history.replaceState({value: 1, value2: X}, "title", "page.php");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...