admin管理员组文章数量:1291147
Good day to all.
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.
It looked like a permission error to me so I changed the file loaded in iframe permissions to 777, but without any result.
Note: The file loaded in iframe is not on the same domain.
Good day to all.
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.
It looked like a permission error to me so I changed the file loaded in iframe permissions to 777, but without any result.
Note: The file loaded in iframe is not on the same domain.
Share Improve this question asked May 23, 2011 at 8:12 zozozozo 8,58219 gold badges83 silver badges140 bronze badges 1- 1 this has been asked many times before: stackoverflow.com/questions/364952/… – ashwoods Commented May 23, 2011 at 8:26
2 Answers
Reset to default 10It'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/.
I am not sure if it is possible, cross window (frame) communication have to be at same domain, protocol and hostname. For more info see Same origin policy for JavaScript and Cross domain communication with iframes
本文标签:
版权声明:本文标题:javascript, iframe, security - Permission denied when tring to access a js function from parent window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739238066a2153523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论