IFrame Child Page method of invoking parent page JavaScript function (common method for chrome and IE support)

Source: Internet
Author: User

How the IFRAME child page invokes the parent page JavaScript function

Today encountered an IFRAME child page called the parent page JS function requirements, the solution is very simple, but in the Chrome browser encountered a small problem. By the way, the parent page of the IFRAME calls the child page JavaScript function method, spare!

1. IFRAME Child page Call parent page JS function

The child page calls the parent page function just to write on window.praent. For example, invoking the A () function is written as:

WINDOW.PRAENT.A ();

But I found this method invalid in Chrome! For a long while to understand, in the chrome 5+, Window.parent cannot run in the FILE://protocol, but after the release of http://protocol can be run. This method supports IE, Firefox browser.

2, the IFRAME Child parent page called the child page JS function

This is a little more complicated, the following methods support IE and Firefox browser:

document.getElementById (' Ifrtest '). contentwindow.b ();

Note: Ifrtest is the id,b () of the IFRAME frame as a sub-page JS function. The Contentwindow property is the window object of the specified frame or IFRAME, which can be omitted under IE.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.