1, JS in the child window to get the parent window windows
Window.parent
At this point you can call the window method of the parent windows, such as getting the height of the parent window window.parent.innerHeight, width window.parent.innerWidth, mobile location of the parent window, etc., specific to see my blog " Get the size of the browser window and some action on the browser window.
2, JS in the parent window to get child windows window
$ ("#testiframe") [0].contentwindow==document.getelementbyid ("Testiframe"). Contentwindow==window.frames[0]
All of the above three kinds of windows can be obtained, the above three corresponding <body> as follows:
<div style= "border:1px solid black;" >
<iframe id= ' testiframe ' height= ' width= ' src= ' xxxxx ' ></iframe>
</div>
3, jquery in the IFRAME child page to get the parent page element code as follows:
$ ("#objid", parent.document);
4. jquery Gets the element of the IFRAME child page on the parent page
The code is as follows:
$ ("#objid", Document.frames (' Iframename '). Document)
5, JS in the IFRAME child page to get the parent page element code as follows:
Window.parent.document.getElementById ("Element id");
6, JS in the parent page to get the IFRAME child page element code is as follows:
window.frames["iframe_id"].document.getelementbyidx_x ("element ID");
7, the child window within the IFRAME call the parent window function:
Parent.func ();
The premise is that the parent window JS must have func () this method.
8, call the child window function in the parent window
document.getElementById (The ID value of the child window Ifram element). Contentwindow. Method in a child window ()
The child window Ifram the element's name value. Window. method in child window ()
One: Layer.open the elements and methods of an IFRAME parent page are invoked with each other
1: JS in the parent page
Layer.open ({
Type:2//Here with an IFRAME example
,
Title: ' <span style= "margin-left:10px" > Add quality complaint record </span > ',
Area: [' 700px ', ' 90% '],
Offset: "RB",
Content: ' views/qualitymanagement/qualitycomplaintrecord/newaddrecord.html ',
ZIndex:layer.zIndex,
Success:function (Layero,index) {
Top.layer.setTop (Layero); Key 2
var BODY = layer.getchildframe (' body ', index);
var Iframewin = window[layero.find (' iframe ') [0][' name ']]; To get the window object of the IFRAME page, execute the method of the IFRAME page
Iframewin.method ();
JS gets the window of child windows in the parent window
$ ("#testiframe") [0].contentwindow==document.getelementbyid ("Testiframe"). Contentwindow==window.frames[0]
Get an IFRAME child page element on the parent page
$ ("#objid", Document.frames (' Iframename '). Document)
Body.find (' input '). Val (' Hi, I'm from the parent page ')
$ (' #default ', Iframewin.document). Val ();
},
Cancel:function () {
},
End:function () {
}
});
2: Sub-page JS
$ (". Addrecord_submit"). Click (function () {
var index = Parent.layer.getFrameIndex (window.name); First get the index of the current IFRAME layer
Parent.layer.close (index); Then perform the shutdown
Child page Call parent page function
Parent.method (); JS gets the windows of the parent window in the child window
Window.parent//Subpages Get parent page elements
$ (' #id ', Window.parent.document). Val ();
})
Two: Parent.layer.open the elements and methods of the IFRAME page call each other
Parent.layer.open ({
Type:2//Here with an IFRAME example
,
Title: ' <span style= "margin-left:10px" > Add quality complaint record </span > ',
Area: [' 700px ', ' 90% '],
Offset: "RB",
Content: ' views/qualitymanagement/qualitycomplaintrecord/newaddrecord.html ',
ZIndex:layer.zIndex,
Success:function (Layero,index) {
Top.layer.setTop (Layero); Key 2
var BODY = layer.getchildframe (' body ', index);
J Get Windows for window
var p1aentifarame = Layero.find ("iframe") [0].contentwindow;
var paentifarame = Layero.find ("iframe") [0].contentwindow.document;
P1aentifarame.method ();
Get an IFRAME child page element on the parent page
$ (' #default ', Paentifarame). Val ()
$ (". Addrecord_submit", Paentifarame). Click (function () {})
},
Cancel:function () {
},
End:function () {
}
});
Third: Get the IFrame page method and element Window.name according to the IFRAME name get the current iframe name
Window. Parent.name Get parent iframe Name
Window.parent.frames[iframename] Gets the current Window object in the parent of the IFRAME named Iframename, through which you can get page methods such as: Window.parent.frames[iframename] . Productlistdata ()
Window.parent.frames[iframename].document
$ (window.parent.frames[iframename].document). Find (". ProductList"). Val () Get the value of an element