Can I Access Contents Of An Iframe From A Subdomain If I Use Www. On The Main Domain?
Solution 1:
Same-Origin-Policy requires the exact same hostname by default.
To tell it not to, set:
document.domain= 'domain.com';
from script in both the parent (www.) document and the iframe (example.) document.
Note that setting an onload of a statically-written iframe (or image) from script is unreliable, as it is conceivable that the iframe might get completely loaded in between the time the parser reads the iframe tag and when it reads the script tag that sets the onload.
To avoid this, either include the event handler as an inline ‘<iframe onload="doSomething()"’ attribute (one of the few places where inline event handling has some purpose), or, if acceptable for accessibility, create the iframe element itself from script, setting the onload before writing the src and adding it to the page.
Post a Comment for "Can I Access Contents Of An Iframe From A Subdomain If I Use Www. On The Main Domain?"