历史 pushState 抛出未捕获的 DOMException [英] History pushState throws Uncaught DOMException

查看:36
本文介绍了历史 pushState 抛出未捕获的 DOMException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I am using the History API and I am trying to use the pushState() function :

<代码>我这样做了:history.pushState({'a': 'b'}, 'Document', "index2.html");

它给了我这个错误:

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

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() 文档原点为 null

如果是这样,那里的答案表明这是有效的:

If so, the answer there indicates that this works:

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

这篇关于历史 pushState 抛出未捕获的 DOMException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆