javascript, iframe, security - Permission denied when tring to access a js function from parent window - Stack Overflow

Good day to all. I have a page that includes an iframe. In that iframe I have a script with function ca

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
Add a comment  | 

2 Answers 2

Reset to default 10

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/.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1739238067a4117687.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信