Kunal Vashist Kunal Vashist - 2 years ago 181
HTML Question

Cross domain iframe issue

For say i have a Site called example.com on which iframe is embedded of domain iframe.net, now i want to read the content of iframe and pass some parameter to display a textual message. Like Hi with username.

Now the problem is this able not able to make connection between the two , even am not able to get the innerHTML of iframe i used following approach


It throws error "Permission denied to access property"

Do anyone know how to read and write in cross domain platform

Answer Source

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) {

// Trigger:
// <iframe id="myframe" src="framed.htm"></iframe>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download