Javascript 未捕获的安全错误:无法在“历史”上执行“replaceState”:无法在原点为“null”的文档中创建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32453806/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 08:04:18  来源:igfitidea点击:

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': cannot be created in a document with origin 'null'

javascriptjquerygoogle-chromejquery-mobile

提问by olivier

I really don't get this chrome error:

我真的没有收到这个 chrome 错误:

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': cannot be created in a document with origin 'null'

未捕获的安全错误:无法在“历史”上执行“replaceState”:无法在原点为“null”的文档中创建

In Edge, Firefox and IE no errors.

在 Edge、Firefox 和 IE 中没有错误。

I use jquery 1.11.1 and jquery mobile 1.4.5.

我使用 jquery 1.11.1 和 jquery mobile 1.4.5。

This is my index file:

这是我的索引文件:

<!DOCTYPE html>
<html>
<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="css/xy.min.css" />
    <link rel="stylesheet" href="css/jquery.mobile.icons.min.css" />
    <link rel="stylesheet" href="css/jquery.mobile.structure-1.4.5.min.css" />

    <title></title>

</head>

<body>
    <div data-role="page">
       <div data-role="header" data-add-back-btn="true">
           <p align="center">Test</p>
       </div>

        <ul data-role="listview" data-filter="true" data-filter-placeholder="Kategorie suchen"  data-inset="true" data-count-theme="b">
            <li><a href="assets/beck/index.html" data-rel"dialog" rel ="external">B?ckereien </a></li>
        </ul>

    </div>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>
</body>

</html>

Any help much appreciated!

非常感谢任何帮助!

回答by eFMer

Add this:

添加这个:

<script>
    $(document).bind('mobileinit',function(){
        $.mobile.changePage.defaults.changeHash = false;
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
    });
</script> 

Just before jquery.mobile-1.4.5.min.js

就在 jquery.mobile-1.4.5.min.js 之前

That works with Android WebViewClient and Chrome on Windows.

这适用于 Windows 上的 Android WebViewClient 和 Chrome。

回答by olivier

The Solution for me was that i have to run a webserver. It's a new chrome security feature and wont be changed according Chromium Bug Post.

我的解决方案是我必须运行一个网络服务器。这是一项新的 chrome 安全功能,不会根据 Chromium Bug Post 进行更改。

Thanks to A. Wolff!

感谢 A. Wolff!

回答by Greg Benedict

This can also be caused by Turbolinks (HTML pushState) when working with a local HTML file.

在使用本地 HTML 文件时,这也可能是由 Turbolinks (HTML pushState) 引起的。