I am working on a CMS site whose domain is:
http://www.acmssite.com
They have a sub-domain where they store a form system:
http://www.forms.acmssite.com
I have an iframe on the first that looks at a form in the latter.
I need to run scripts to manipulate the latter from the former and was wondering is this possible?
A page inside an iframe is not allowed to access or modify the DOM of its parent and vice-versa unless both have the same origin. So putting it in a different way: document or script loaded from one origin is prevented from getting or setting properties of a document from another origin.
To access cross-domain iframe, the best approach is to use Javascript's postMessage() method. This method provides a way to securely pass messages across domains.
Sub-domains are considered different and will fail the Same Origin Policy unless both sub-domains declare the same document. domain DOM property (and even then, different browsers behave differently).
You cannot detect click events in cross-domain iframe. However it's not reliable, loose focus does not mean a click, it could be user moving across the website using TAB .
In order for this to not be restricted by the same origin policy, you will probably need to do this in both the pages:
document.domain = "acmssite.com";
Yes it is.
var iframe = document.getElementById("your-iframes-id").contentWindow.document;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With