【发布时间】:2012-05-09 22:49:23
【问题描述】:
从页面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,但我认为问题不在于这里):
(function() {
$('#ipad-viewport iframe').bind('load', function() {
return console.log($(this).contents().find('map'));
});
}).call(this);
我等待加载 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 进行测试。
【问题讨论】:
-
似乎 file:// 并不是测试 JS/AJAX 的最佳包装器/protocoll。
-
这不是一个 ajax 请求,我没有在服务器上运行,因为到目前为止还没有服务器端的工作要做。
-
总是在服务器上运行它,这是测试它是否有效的最佳方法
-
去掉返回,不要返回事件内部的东西,也许这会有所帮助。
标签: javascript jquery security