Home >Web Front-end >JS Tutorial >How Can I Access Parent Window Functions from Inside an iFrame?

How Can I Access Parent Window Functions from Inside an iFrame?

Susan Sarandon
Susan SarandonOriginal
2024-12-01 21:26:12934browse

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:

  • [window.parent](https://developer.mozilla.org/en-US/docs/Web/API/Window/parent)
  • [Calling Parent Window Methods from Iframes](https://www.c-sharpcorner.com/Blogs/calling-parent-window-methods-from-iframes)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn