Cross domain iframe issue

If you don’t have control over the framed site, you cannot circumvent the cross-domain policy.

If you have control over both sites, you can use the postMessage method to transfer data across different domains. A very basic example:

// framed.htm:
window.onmessage = function(event) {
    event.source.postMessage(document.body.innerHTML, event.origin);
};

// Main page:
window.onmessage = function(event) {
    alert(event.data);
};

// Trigger:
// <iframe id="myframe" src="https://stackoverflow.com/questions/9393532/framed.htm"></iframe>
document.getElementById('myframe').contentWindow.postMessage('','*');

Leave a Comment