【问题标题】:Failed to execute 'replaceState' on 'History' <local_URL> cannot be created in a document with origin 'null'未能在“历史”上执行“replaceState” <local_URL> 无法在原始“null”的文档中创建
【发布时间】:2015-12-05 12:33:54
【问题描述】:

我正在为过渡创建一个页面。

单击页面导航到另一个页面 - 在 Firefox 上有效,但在 Chrome 上无效。

显示错误:

未捕获的安全错误:无法在“历史记录”上执行“replaceState”:
无法在来源为“null”的文档中创建 URL 为“file:///C:/Users/athite/Desktop/DEMO/page.html”的历史状态对象。**

这是我的代码:

<!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>

【问题讨论】:

    标签: javascript jquery html google-chrome jquery-mobile


    【解决方案1】:

    问题出现在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>
    

    【讨论】:

    • 这解决了这个问题。但是,移动应用程序上使用的主题现在搞砸了。知道它的根本原因是什么吗?
    猜你喜欢
    • 2018-08-03
    • 2015-12-03
    • 1970-01-01
    • 2018-07-02
    • 2018-09-12
    • 1970-01-01
    • 2020-11-16
    • 2014-11-01
    • 1970-01-01
    相关资源
    最近更新 更多