Chrome SecurityError 从本地文件系统加载 jQuery Mobile 页面 [英] Chrome SecurityError loading jQuery Mobile page from local file system

查看:20
本文介绍了Chrome SecurityError 从本地文件系统加载 jQuery Mobile 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Chrome 中使用 jQuery Mobile 引用加载一个简单的 html 文件时出现以下错误.错误不存在于仅 jQuery 参考中.

I get the following error in Chrome when loading a trivially simple html file with a jQuery Mobile reference. The error is not present with just the jQuery reference.

未捕获的安全错误:无法在历史"上执行replaceState":带有 URL 'http://stacksnippets.net/js' 的历史状态对象不能在原点为null"的文档中创建.

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://stacksnippets.net/js' cannot be created in a document with origin 'null'.

<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body></body>
</html>

您还可以运行代码片段"并在控制台中查看错误.

You can also "Run code snippet" and see the error in the console.

这个错误在今天之前没有发生.我没有更改在浏览器中加载 html 文件的代码或方法.它过去运行良好 - 我对所有 PhoneGap 应用程序使用相同的代码.

This error did not happen before today. I have not changed my code or method of loading the html file in the browser. It used to work perfectly - I use the same code for all my PhoneGap apps.

有谁知道是否有 Chrome 安全更新导致了这个 SecurityError 或者我是否遗漏了什么?你会如何调试这个?谢谢.

Does anyone know if there was a Chrome security update that causes this SecurityError or whether I'm missing something? How would you go about debugging this? Thank you.

更新

我认为这个讨论指出了正在发生的事情,这是我怀疑的,因为在使用 Web 服务器运行时不会出现错误:Access-Control-Allow-Origin 不允许空值.

This discussion I think points out what is going on, which I suspected, since the error does not appear when running with a web server: Origin null is not allowed by Access-Control-Allow-Origin .

但我仍然想知道为什么这在过去的一天发生了变化,Chrome 的安全策略是否发生了变化,或者为什么它以前可以工作,以及我的任何 PhoneGap 应用程序是否会受到影响.

But I am still wondering why this changed in the past day, whether Chrome has had a change in their security policy, or why it was working before, and whether any of my PhoneGap apps will be affected.

推荐答案

此错误与 origin is null 错误相同.发生此错误的原因是 Chrome 的安全功能.测试应用程序的一个简单解决方案是绕过 Chrome 上的此安全性.

This error is same as the origin is null error. This error occurs because of the security feature of Chrome. A simple solution to test the application is to bypass this security on chrome.

步骤:

  1. 在桌面上创建一个 Chrome 浏览器快捷方式.
  2. 关闭您机器上的所有 chrome 实例.
  3. 右键单击 chrome 的桌面快捷方式,然后单击属性".
  4. 在目标字段中,在末尾附加-allow-file-access-from-files".
  5. 保存并关闭属性.
  6. 仅通过此快捷方式打开 chrome.

快点,错误消失了.应用完美运行.

Hurry, the error has gone. App works perfectly.

注意:这只是我用来在桌面浏览器上测试我的cordova 应用程序以进行UI 测试的一种变通方法.

NOTE: This is just a work-around I use to test my cordova apps on desktop browser for UI testing.

这篇关于Chrome SecurityError 从本地文件系统加载 jQuery Mobile 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆