javascript 无法在“历史”上执行“replaceState”<local_URL> 无法在原点为“null”的文档中创建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32481260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to execute 'replaceState' on 'History' <local_URL> cannot be created in a document with origin 'null'
提问by Learner
I am creating a page for the transition.
我正在为过渡创建一个页面。
Clicking on the page to navigate to another page - works on Firefox, but it doesn't on Chrome.
单击页面以导航到另一个页面 - 适用于 Firefox,但不适用于 Chrome。
Error is showing :
错误显示:
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'.**
未捕获的安全错误:无法在“历史”上执行“replaceState”:无法
在原始文档中创建 URL 为“file:///C:/Users/athite/Desktop/DEMO/page.html”的历史状态对象空值'。**
Here is my code:
这是我的代码:
<!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>
回答by Nishanthi Grashia
The issue occured in jquery.mobile-1.4.5.min.js:3
问题发生在 jquery.mobile-1.4.5.min.js:3
Solution:
解决方案:
Add this script before import as follows:
在导入之前添加此脚本,如下所示:
<script>
$(document).bind('mobileinit',function(){
$.mobile.pushStateEnabled = false;
});
</script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>