. Advertisement .
..3..
. Advertisement .
..4..
I get the error: blocked a frame with origin from accessing a cross origin frame when I try to run the program below:
$(document).ready(function() {
var iframeWindow = document.getElementById("my-iframe-id").contentWindow;
iframeWindow.addEventListener("load", function() {
var doc = iframe.contentDocument || iframe.contentWindow.document;
var target = doc.getElementById("my-target-id");
target.innerHTML = "Found it!";
});
});
The error appears the system notifies as follows:
SecurityError: Blocked a frame with origin "http://www.<domain>.com" from accessing a cross-origin frame.
I tried to solve it with another sample. I got the reference in the community forum, but it still returned an invalid result. If someone knows the solution, please give me the support. Thanks!
The cause: You cannot access a
<iframe>
of a different origin using JavaScript. This would be a serious security problem. The same origin policy browsers blocks scripts trying access a frame with an alternative origin.Solution:
If at least one of these parts of an address isn’t maintained, origin is considered to be different
If you wish to access a frame, the protocol, hostname, and port must match your domain.
Marco Bonelli’s response is complete. The best way to interact between frames/iframes at the moment is using
window.postMessage
. This support browsers.