历史pushState抛出未捕获的DOMException

问题描述 投票:0回答:1

所以我正在使用History API,并且试图使用pushState()函数:

I did this: history.pushState({'a': 'b'}, 'Document', "index2.html");

它给我这个错误:

未捕获的DOMException:无法在'History'上执行'pushState':不能在原始'null'和URL'...'的文档中创建具有URL'...'的历史状态对象。

javascript api history
1个回答
0
投票

是这个问题吗?replaceState() with document origin null

如果是这样,那里的答案表明这可行:

history.replaceState(null,null, window.location.pathname + "your thing here");
© www.soinside.com 2019 - 2024. All rights reserved.