javascript,iframe,security - 当从父窗口访问js函数时,权限被拒绝 [英] javascript, iframe, security - Permission denied when tring to access a js function from parent window

查看:936
本文介绍了javascript,iframe,security - 当从父窗口访问js函数时,权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好日子。

我有一个包含iframe的页面。在那个iframe中,我有一个名为test()的脚本。我需要从父窗口访问该函数。在询问后我得到了这个解决方案:

I have a page that includes an iframe. In that iframe I have a script with function called test(). I need to access the function from the parent window. After asking around I got to this solution:

<div onclick="document.getElementById('targetFrame').contentWindow.teste();">Test</div>

点击后,应运行测试功能。问题是我得到权限被拒绝访问属性测试错误。

On click the test function should be run. The problem is that I get " Permission denied to access property test" error.

它看起来像是一个权限错误,因此我将iframe权限中加载的文件更改为777 ,但没有任何结果。

It looked like a permission error to me so I changed the file loaded in iframe permissions to 777, but without any result.

注意:iframe中加载的文件不在同一个域中。

Note: The file loaded in iframe is not on the same domain.

推荐答案

默认情况下禁止从其他域访问页面,因为浏览器使用同源策略。有几种解决方法,比如使用location.hash或window.name在帧之间进行通信。 HTML5中最新和标准化的是postMessage-interface。
有一个跨浏览器解决方案的库 http://easyxdm.net/wp/

It's prohibited to access pages from other domains by default, because browsers use same origin policy. There are several workaround like using location.hash or window.name to communicate between frames. The most recent and standardized in HTML5 is postMessage-interface. There is library for cross-browser solution http://easyxdm.net/wp/.

这篇关于javascript,iframe,security - 当从父窗口访问js函数时,权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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