Js/Jquery get the elements in iframe get the Element Method of the parent form in Iframe

Source: Internet
Author: User

Iframe is often used in web development, and elements that need to be used in the iframe in the parent window or in the iframe framework

Js
Obtain the elements in IFRAME in the parent window.
1,
Format: window. frames ["iframe name value" 2.16.doc ument. getElementByIdx_x ("Control ID in iframe"). click ();
Example: window. frames ["ifm" mirror.doc ument. getElementByIdx_x ("btnOk"). click ();
2,
Format:
Var obj = document. getElementByIdx_x ("iframe name"). contentWindow;
Var ifmobj1_obj.doc ument. getElementByIdx_x ("Control ID in iframe ");
IfmObj. click ();
Instance:
Var obj = document. getElementByIdx_x ("ifm"). contentWindow;
Var ifmobj1_obj.doc ument. getElementByIdx_x ("btnOk ");
IfmObj. click ();
Get the elements of the parent window in IFRAME
Format: Required parameter parent.doc ument. getElementByIdx_x ("parent window element ID"). click ();
Example: Response response parent.doc ument. getElementByIdx_x ("btnOk"). click ();

Jquery
Obtain the elements in IFRAME in the parent window.
1,
Format: $ ("# iframe id"). Contents (). Find ("# Control ID in IFRAME"). Click (); // jquery method 1
Example: $ ("# IFM"). Contents (). Find ("# btnok"). Click (); // jquery method 1
2,
Format: $ ("# Control ID in IFRAME", document. Frames ("frame name" ).doc ument). Click (); // jquery method 2
Example: $ ("# btnok", document. Frames ("IFM" example .doc ument). Click (); // jquery method 2
Get the elements of the parent window in IFRAME
Format: $ ('# element ID in the parent window', parent.doc ument). Click ();
Instance: $ ('# btnok', parent.doc ument). 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.