[英]Uncaught DOMException: Failed to execute 'pushState' on 'History':
I have an issue that presents itself in different scenarios depending on the user.我有一个问题,根据用户的不同,它会出现在不同的场景中。
Group A: When what seems to be select users loads into the homepage and click a navigation anchor which should load with AJAX and use history.pushState('', '', destinationUrl); A 组:当似乎是选择的用户加载到主页并单击应使用 AJAX 加载并使用 history.pushState('', '', destinationUrl); 的导航锚点时; they receive no response.他们没有收到任何回应。 An error message displays in console:控制台中显示错误消息:
Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL ' http://example.net/foo ' cannot be created in a document with origin ' http://www.example.net ' and URL ' http://www.example.net/ '未捕获的 DOMException:无法在“History”上执行“pushState”:无法在来源为“ http://www.example.net ”的文档中创建 URL 为“ http://example.net/foo ”的历史状态对象和 URL ' http://www.example.net/ '
Based on searches I figured the issue would be not including www in example.net/foo.根据搜索,我认为问题不包括在 example.net/foo 中的 www。 I updated the navigation anchors to " http://www.example.net/foo ".我将导航锚点更新为“ http://www.example.net/foo ”。
This fixed the issue for Group A but created the same issue for the larger user base Group B with a similar error:这修复了 A 组的问题,但为更大的用户群 B 组创建了相同的问题,并出现类似错误:
Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL ' http://www.example.net/foo ' cannot be created in a document with origin ' http://example.net ' and URL ' http://example.net/ '.未捕获的 DOMException:无法在“History”上执行“pushState”:无法在来源为“ http://example.net ”的文档中创建 URL 为“ http://www.example.net/foo ”的历史状态对象和 URL ' http://example.net/ '。
For Group B the url discrepancy is inverted.对于 B 组,url 差异被反转。 The issue appears to be browser independent for both groups.该问题似乎与两个组的浏览器无关。 The site uses Craft CMS.该网站使用工艺 CMS。
Any direction or solutions to what might be happening, how can I fix this for both groups?任何可能发生的事情的方向或解决方案,我如何为这两个群体解决这个问题?
Thanks to @Patrick Evans.感谢@Patrick Evans。 The recommendation to use mod_rewrite led me here: https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost使用 mod_rewrite 的建议让我在这里: https : //httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost
I ultimately used the "if" directive recommendation but also tested mod_rewrite and it worked as well.我最终使用了“if”指令推荐,但也测试了 mod_rewrite 并且它也有效。
<If "%{HTTP_HOST} != 'www.example.net'">
Redirect "/" "http://www.example.net/"
</If>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.