Is it possible for me to setup an iframe so it calls a javascript function available in the window.parent.document
scope?
To call a parent window function, use “window. top”.
When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.
Calling a parent JS function from iframe is possible, but only when both the parent and the page loaded in the iframe are from same domain i.e. example.com , and both are using same protocol i.e. both are either on http:// or https:// .
If a user has javascript disabled, iframes will work. An iframe tag has attributes “height” and “width,” which allows the designer great latitude with dimensions and format like 300×250 , 728×90 depending on the Ad size. Iframe tag can appear anywhere on the page and several iframes can be added if wished to.
If I am understanding the question correctly, assuming functionName()
is defined within the parent of iframe, you can do this within your iframe:
window.parent.functionName();
This will only work though, if both parent and iframe are on the same domain: http://softwareas.com/cross-domain-communication-with-iframes
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