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

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

问题描述

使用jQuery Mobile参考加载简单的html文件时,Chrome中出现以下错误。
$ b


未捕获的SecurityError:未能在'History'上执行'replaceState':
具有URL' http://stacksnippets.net/js '的历史状态对象不能
在源文件中创建'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>  



您也可以运行代码片段控制台。



这个错误并不值得今天之前。我没有改变我的代码或在浏览器中加载html文件的方法。它曾经完美地工作 - 我为我所有的PhoneGap应用程序使用相同的代码。



有谁知道是否有Chrome安全更新导致此SecurityError,我错过了什么?你将如何去调试呢?谢谢。



更新



这个讨论我想指出发生了什么事上,我怀疑,因为错误不会出现时运行Web服务器: Origin-null不允许通过Access-Control-Allow-Origin



但我仍然想知道为什么在过去一天,Chrome是否改变了他们的安全策略,或者之前为什么这样做,以及我的PhoneGap应用程序是否会受到影响。

解决方案

这个错误与原始错误是一样的。由于Chrome的安全功能而发生此错误。
一个简单的测试应用程序的方法是在Chrome上绕过这个安全性。

步骤:


  1. 在桌面上创建chrome浏览器快捷方式。

  2. 关闭计算机上所有chrome实例。 $ b
  3. 在chrome的桌面快捷方式上单击鼠标右键,然后单击目标字段中的属性。

  4. ,在末尾附加-allow-file-access-from-files。

  5. 保存并关闭属性。

  6. 仅通过此快捷方式打开chrome。

快点,错误消失了。应用程序完美运行。



注意:这仅仅是我用于在桌面浏览器上测试我的cordova应用程序以进行UI测试的解决方法。 / p>

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.

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.

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.

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.

UPDATE

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 .

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.

解决方案

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.

Steps:

  1. create a chrome browser shortcut on desktop.
  2. Close all the instances of chrome on your machine.
  3. Right click on the desktop shortcut of chrome and click on Properties.
  4. in Target field, append " -allow-file-access-from-files" at the end.
  5. Save and close properties.
  6. Open chrome via this shortcut only.

Hurry, the error has gone. App works perfectly.

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天全站免登陆