admin管理员组文章数量:1241151
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?
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?
3 Answers
Reset to default 4If 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");
No, because the query string is part of the URL. If you don't truly need to pass those values for the purposes of the server, you can include them in the history's state object itself, and then you can change just the state object with pushState()
. For example:
history.pushState({value: 1, value2: 2}, "Title", 'page.php');
history.pushState({value: 1, value2: 'new value'}, "Title");
You can use this useful function to change a query string parameter value:
function updateParam(url, param, value)
{
var re = new RegExp(param+"(.+?)(&|$)","g");
return url.replace(re, param+'='+value)
}
本文标签: javascripthistorypushState() change query valuesStack Overflow
版权声明:本文标题:javascript - history.pushState() change query values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740097917a2224316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论