Home >Web Front-end >JS Tutorial >How Can I Access Parent Window Functions from Inside an iFrame?
Accessing Parent Window Functions from Within an iFrame
When working with iFrames, developers often need to interact with the parent window from the iframe. This involves invoking JavaScript functions defined in the parent window from within the iframe.
Calling a Specific Function
To call a specific parent window function, use the following syntax:
<button onclick="parent.functionName();">Call Parent Function</button>
In your example, to call the abc() function from within the iFrame, modify the hyperlink as follows:
<a onclick="parent.abc();" href="#">Call Me</a>
Understanding parent Property
The parent property in JavaScript represents the parent window of the current window or subframe. If the current window has no parent, the parent property will refer to the window itself.
When an iFrame is loaded within a parent window, the parent property of the iFrame will refer to the parent window. This allows scripts within the iframe to access functions and properties of the parent window.
Additional Resources
For more information on accessing the parent window from an iframe, refer to the following resources:
The above is the detailed content of How Can I Access Parent Window Functions from Inside an iFrame?. For more information, please follow other related articles on the PHP Chinese website!