Js and jQuery get the iframe of the parent window and child window
- 2020-03-30 01:00:26
- OfStack
In web development, iframes are often used, and it is inevitable that you will encounter elements that require the use of the iframe in the parent window, or the use of the parent window in the iframe frame
js
Gets the element in the iframe in the parent window
1.
Format: the window frames [r]. "the iframe name value" document. The getElementByIdx_x (" ID "controls in the iframe). Click ();
Instance: window frames [r]. "imf" document. The getElementByIdx_x (" btnOk "). Click ();
2,
Format:
Var obj = document. GetElementByIdx_x (" the iframe name "). The contentWindow;
Var ifmObj = obj. Document. GetElementByIdx_x (" iframe controls ID ");
IfmObj. Click ();
Example:
Var obj = document. GetElementByIdx_x (" imf "). The contentWindow;
Var ifmObj = obj. Document. GetElementByIdx_x (" btnOk ");
IfmObj. Click ();
Gets the element of the parent window in the iframe
Format: window. The parent. Document. GetElementByIdx_x (" parent window element ID "). Click ();
Example: the window. The parent. The document. GetElementByIdx_x (" btnOk "). Click ();
jquery
Gets the element in the iframe in the parent window
1.
Format: $(" # iframe ID "). The contents (.), find (" # controls within the iframe ID "). Click (); 1 / / jquery method
Instance: $(" # ifm "). The contents (.), find (" # btnOk "). Click (); 1 / / jquery method
2,
Format: $(" control ID in #iframe ",document.frames(" name of frame ").document).click(); 2 / / jquery method
Example: $(" # btnOk ", the document. The frames (" imf "). The document). Click (); 2 / / jquery method
Gets the element of the parent window in the iframe
Format: $('# element ID' in parent window, parent-document).click();
Example: $('#btnOk', parent-document).click();