Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不安全的JavaScript试图使用URL访问帧(同一域!)_Javascript_Jquery_Security - Fatal编程技术网

不安全的JavaScript试图使用URL访问帧(同一域!)

不安全的JavaScript试图使用URL访问帧(同一域!),javascript,jquery,security,Javascript,Jquery,Security,从页面file://localhost/Users/pistacchio/dev/epress/catflow/test_html/index.html我有以下(coffeescript)代码试图访问iframe: $('#ipad-viewport iframe').bind 'load', () -> console.log $(this).contents().find('map') (这转化为以下javascript,但我认为问题不在于此): 我等待iframe页面加载并

从页面
file://localhost/Users/pistacchio/dev/epress/catflow/test_html/index.html
我有以下(coffeescript)代码试图访问iframe:

$('#ipad-viewport iframe').bind 'load', () ->
    console.log $(this).contents().find('map')
(这转化为以下javascript,但我认为问题不在于此):

我等待iframe页面加载并尝试访问其主体中的元素。我得到以下错误:

Unsafe JavaScript attempt to access frame with URL file://localhost/Users/pistacchio/dev/epress/catflow/test_html/catalogo/catalog/intro.html from frame with URL file://localhost/Users/pistacchio/dev/epress/catflow/test_html/index.html. Domains, protocols and ports must match.
现在,由于iframe的定义如下:

<iframe src="file://localhost/Users/pistacchio/dev/epress/catflow/test_html/catalogo/catalog/intro.html" width="1024" height="768"></iframe>

我的页面和iframe不都在同一个域中吗,或者
file://localhost
?为什么我会遇到这个问题


哦,如果相关的话,我正在用Chrome 18测试这一点。

文件://
URL遵循的javascript安全策略与适用于托管内容的正常
同源策略
略有不同。为了阻止保存的网页读取磁盘的全部内容,不同的文件被视为不同的来源。只需启动一个本地服务器,并在其上托管您的内容;您将回到“标准”策略,其中来源由域/ip定义

如果由于某种原因您无法运行web服务器,您可能会从中获得一些好处
命令行开关:
--允许从文件访问文件
。我相信这会使所有
文件://
URL被定义为属于同一来源。

文件://
URL受javascript安全策略的约束,与适用于托管内容的正常
同一来源策略
略有不同。为了阻止保存的网页读取磁盘的全部内容,不同的文件被视为不同的来源。只需启动一个本地服务器,并在其上托管您的内容;您将回到“标准”策略,其中来源由域/ip定义

如果由于某种原因您无法运行web服务器,您可能会从中获得一些好处
命令行开关:
--允许从文件访问文件
。我相信这会使所有
文件://
URL被定义为属于同一来源。

似乎文件://不是测试JS/AJAX的最佳包装器/协议。这不是AJAX请求,我没有在服务器上运行,因为到目前为止,没有服务器端工作要做。只要始终在服务器上运行它,测试JS/AJAX是否有效的最佳方法删除返回,不要在事件中返回某些内容,也许这会有所帮助。似乎file://不是测试JS/AJAX的最佳包装器/protocoll。这不是AJAX请求,我没有在服务器上运行,因为到目前为止没有服务器端工作要做。只要始终在服务器上运行它,测试它是否工作的最佳方法删除返回,不要在事件内部返回某些内容,也许这会有所帮助。虽然这是我能找到的最接近确定答案,但我不确定“--allow file access from files”(允许从文件访问文件)开关有什么相关性-它是用于。。。特定浏览器?Java?命令行参数是针对Chrome的,回应OP说他在使用Chrome 18。虽然这是我能找到的最接近确定答案,但我不确定“--allow file access from files”(允许从文件访问文件)开关有什么关联-它是针对。。。特定浏览器?Java?命令行参数是针对Chrome的,以回应OP说他正在使用Chrome18
<iframe src="file://localhost/Users/pistacchio/dev/epress/catflow/test_html/catalogo/catalog/intro.html" width="1024" height="768"></iframe>