This article introduces how to obtain the iframe of the parent window and sub-window from js and jQuery. For more information, see iframe, it is inevitable that elements in iframe need to be used in the parent window, or elements that use the parent window 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 ();