gpt4 book ai didi

html - replaceState() : a history state with url . .. 无法在具有来源的文档中创建

转载 作者:太空狗 更新时间:2023-10-29 13:29:42 28 4
gpt4 key购买 nike

我有window.history.replaceState(null, null, 'about');main.js位于 required/javascripts在我的服务器上。

然后在关于页面(位于我服务器上的 /(根目录))上,我有一个使用 window.history.replaceState(null, null, 'about:me'); 的链接在本页面。一切正常,但是当我单击另一个具有相同功能但带有 about:girlfriend 的链接时作为 URL,我收到此错误消息:

Uncaught SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'about:girlfriend' cannot be created in a document with origin 'http://my.domain.com'.

我不知道为什么我的浏览器(最新版本的 Chrome)认为我正在尝试使用 pushState 访问此页面而且我不知道为什么我会收到此错误消息,无论我已经阅读了多少次。有人可以为我解释一下吗?我不使用 History.js为此。

值得一提的是,如果我更改 :,我不会收到此错误消息到别的东西,比如 -/ .我想用 :因为/不工作(404 页面未找到)和 -不适合 - 使用 : 会更好.

最佳答案

如果您尝试在本地执行此操作,则以下内容适用于本地和远程加载的页面:

history.replaceState(null,null, window.location.pathname + "your thing here")

关于html - replaceState() : a history state with url . .. 无法在具有来源的文档中创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723654/

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