历史 pushState 抛出未捕获的 DOMException

History pushState throws Uncaught DOMException

所以我正在使用历史记录 API 并且我正在尝试使用 pushState() 函数 :

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

它给我这个错误:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL '...' cannot be created in a document with origin 'null' and URL '...'.

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

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

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