Elements interoperate between parent and child pages (IFrame sub-page)

Source: Internet
Author: User

Js/jquery How to get the elements in an iframe child page:

First, use window.frames["iframe ID"] to get the element

function () {        varwindow.frames["Oiframe"]. document.getElementById ("GetFrame");        Console.log (oiframe);}

Note: Be sure to add window.onload or domcontentloaded here, that is, after the DOM is loaded or the page is loaded.

Second, using Window.name to get the element

var oidframe = window. oiframe. document.getElementById ("GetFrame"); Console.log (oidframe);
Oiframe is the Name property value of the IFRAME, which does not have to be written in window.onload or domcontentloaded, please test it yourself.

Third, using getElementById to get the element
var  document.getElementById ("Oiframe").  Contentwindow. document.getElementById ("GetFrame"); Console.log (oidframe);

After using document.getElementById to get the IFRAME element for this page, get the elements of the IFRAME child page. This method of acquisition does not have to be written in window.onload or domcontentloaded

Iv. using jquery to get

var ojiframe = $ ("#oIframe"). Contents (). Find ("#getFrame"). html (); Console.log (ojiframe);

Js/jquery iframe child page Gets the parent page element method:

First, the use of JS

var fatherele = window.parent.document.getElementById ("title"); Console.log (Fatherele);

Ii. Use of JQ

var fatherelejq = $ ("#title", parent.document); Console.log (FATHERELEJQ);

Parent page:

<DivID= "title">Index contains IFRAME sub-page</Div>    <DivID= "Parent">        <iframename= "Oiframe"ID= "Oiframe"src= "iframe.html"frameborder= "0"width= "+"Height= "562"></iframe></Div>

Iframe.html Sub-page:

<id= "GetFrame">iframe</div>

Reference Link: http://java-my-life.iteye.com/blog/1275205

Elements interoperate between parent and child pages (IFrame sub-page)

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.