gpt4 book ai didi

javascript - 无法在 'replaceState' 上执行 'History' 无法在源为 'null' 的文档中创建

转载 作者:太空狗 更新时间:2023-10-29 13:59:28 26 4
gpt4 key购买 nike

我正在为转换创建一个页面。

点击页面导航到另一个页面 - 适用于 Firefox,但不适用于 Chrome。

显示错误:

Uncaught SecurityError: Failed to execute 'replaceState' on 'History':
A history state object with URL 'file:///C:/Users/athite/Desktop/DEMO/page.html' cannot be created in a document with origin 'null'.**

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>

<div data-role="page" id="pageone">
<div data-role="header">
<h1>Welcome To My Homepage</h1>
</div>

<div data-role="main" class="ui-content">
<p>Click on the link to see the slide effect.</p>
<a href="#pagetwo" data-transition="slide">Slide to Page Two</a>
</div>

<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>

<div data-role="page" id="pagetwo">
<div data-role="header">
<h1>Welcome To My Homepage</h1>
</div>

<div data-role="main" class="ui-content">
<p>Click on the link to go back. </p>
<a href="#pageone" data-transition="slide" data-direction="reverse">Go to Page One</a>
</div>

<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>

</body>
</html>

最佳答案

问题发生在 jquery.mobile-1.4.5.min.js:3

解决方案:

在导入之前添加此脚本如下:

<script>
$(document).bind('mobileinit',function(){
$.mobile.pushStateEnabled = false;
});
</script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>

关于javascript - 无法在 'replaceState' 上执行 'History' <local_URL> 无法在源为 'null' 的文档中创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32481260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com