【问题标题】:History pushState throws Uncaught DOMException [duplicate]历史 pushState 抛出 Uncaught DOMException [重复]
【发布时间】:2019-12-27 10:28:28
【问题描述】:

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

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

它给了我这个错误:

未捕获的 DOMException:无法在“历史”上执行“pushState”:无法在源为“null”且 URL 为“...”的文档中创建 URL 为“...”的历史状态对象。

【问题讨论】:

    标签: javascript api history.js


    【解决方案1】:

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

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

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

    【讨论】:

    • 是的,就是这样,谢谢你的回答。
    猜你喜欢
    • 2018-03-06
    • 2019-09-16
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多