The iframe_javascript technique of getting the parent window and the sub window by JS and jquery

Source: Internet
Author: User

In web development, an IFRAME is often used, inevitably encountering elements that need to be used in an IFRAME in the parent window, or that use the parent window in an iframe frame.

Js

Get the elements in the IFRAME in the parent window

1,

Format: window.frames["The name value of the IFRAME"].document.getelementbyidx_x ("ID of the control in the IFrame"). Click ();

Example: window.frames["IFM"].document.getelementbyidx_x ("Btnok"). Click ();

2,

Format:

var obj=document.getelementbyidx_x ("Name of the IFrame"). Contentwindow;

var ifmobj=obj.document.getelementbyidx_x ("ID of the control in the IFrame");

Ifmobj.click ();

Instance:

var obj=document.getelementbyidx_x ("IFM"). Contentwindow;

var ifmobj=obj.document.getelementbyidx_x ("Btnok");

Ifmobj.click ();

Gets the element of the parent window in the IFRAME

Format: window.parent.document.getElementByIdx_x (the element ID of the parent window). Click ();

Example: window.parent.document.getElementByIdx_x ("Btnok"). Click ();

Jquery

Get the elements in the IFRAME in the parent window

1,

Format: $ ("#iframe的ID"). Contents (). Find ("#iframe中的控件ID"). Click ();//jquery Method 1

Instance: $ ("#ifm"). Contents (). Find ("#btnOk"). Click ();//jquery Method 1

2,

Format: $ ("#iframe中的控件ID", Document.frames ("Name of Frame"). Document). Click ();//jquery Method 2

Instance: $ ("#btnOk", Document.frames ("IFM"). Document). Click ();//jquery Method 2

Gets the element of the parent window in the IFRAME

Format: $ (' #父窗口中的元素ID ', parent.document). Click ();

Example: $ (' #btnOk ', parent.document). Click ();

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.