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 ();