Javascript, iframe, security - Permission denied when calling tring to access js function from parent window

Good day to all.

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

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

When clicked, the test function should be launched. The problem is that I get the "Permission to Deny Access to Properties" error message.

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

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

+5
source share
2 answers

Access to pages from other domains by default is forbidden because browsers use the same origin policy . There are several workarounds, for example, using location.hash or window.name to communicate between frames. The latest and standardized in HTML5 is the postMessage interface. There is a library for cross-browser solution http://easyxdm.net/wp/ .

+10
source

I’m not sure if this is possible, the internetwork (frame) message should be in the same domain, protocol and host name. For more information, see Same Source Policy for JavaScript and Cross-Domain Communication with iframes

+3

All Articles