Home > Web Front-end > JS Tutorial > How to Access the Parent Iframe from JavaScript?

How to Access the Parent Iframe from JavaScript?

DDD
Release: 2024-11-06 04:16:02
Original
804 people have browsed it

How to Access the Parent Iframe from JavaScript?

Accessing Parent Iframe from JavaScript

When working with multiple Iframes on the same domain, it becomes essential to access information from the parent Iframe to facilitate seamless communication and control. Here's how you can achieve this:

<iframe>
Copy after login

In the parent page, assign a unique name to the iframe.

parent.document.getElementById(window.name);
Copy after login

On the child page, use the above code to access the parent Iframe object. This approach allows you to establish a direct reference to the parent Iframe from the child page.

Additional Notes:

  • Use the same name and ID for the iframe to simplify access.
  • If there are multiple Iframes with the same page, you can maintain an array of references to distinguish them.
  • This technique is especially useful when you need to close specific Iframes dynamically from the child page.

The above is the detailed content of How to Access the Parent Iframe from JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template