Failed to execute 'replaceState' on 'History' <local_URL> cannot be created in a document with origin 'null'

我与影子孤独终老i 提交于 2019-12-18 03:41:43

问题


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.

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'.**

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>

回答1:


The issue occured in 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>


来源:https://stackoverflow.com/questions/32481260/failed-to-execute-replacestate-on-history-local-url-cannot-be-created-in-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!