gpt4 book ai didi

javascript - js 在使用 history.pushstate 后设置默认 url

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:44 27 4
gpt4 key购买 nike

我有一个问题。如何从 history.pushState 添加的 url“内容”中删除?例如我有一个这个网址:

site.com

好的,现在我将此 url 更新为:

site.com/site/subsite

如何恢复默认 url (site.com)。

我尝试 history.pushState("",document.title,document.location.pathname) 但是,

document.location.pathname 是“site.com/site/subsite”

然后我回到起点:(

最佳答案

history.pushState("", document.title, "/");

它将从域 url 中完全删除状态。

关于javascript - js 在使用 history.pushstate 后设置默认 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9048197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com