replaceState():具有url的历史状态...无法在具有origin的文档中创建

Eri*_*rik 9 html5 html5-history

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

然后在about页面(位于/我的服务器上的(root)),我有一个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 Page Not Found)并且-不适合 - 它更好用:.

小智 6

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

history.replaceState(null,null, window.location.pathname + "your thing here")
Run Code Online (Sandbox Code Playgroud)