First case: The method of name and ID does not exist in the IFRAME: (obtained by Contentwindow) var iframe = document.getElementsByTagName (' iframe ') [0];
var ifr_document = The contents of the document in Iframe.contentwindow.document;//iframe or:var _iframe = document.getelementbyidx_x (' Iframeid '). Contentwindow; var _div =_iframe.document.getelementbyidx_x (' objId ');
or:
- var framewin=document.getElementById (' iframe '). Contentwindow; Window Object
- var framedoc=document.getElementById (' Iframeid '). Contentwindow.document//document Object
- var framebody=document.getElementById (' Iframeid '). ContentWindow.document.body//body to
Second case: The method of name or ID in the IFRAME: (obtained via frames[] array) document.frames[' iframe name '].document.getelementbyid (' element id '); Third case: Get the ID element of the parent page in the IFRAME: Varobj=window.parent.document.getElementById (' objId ');
$ (window.parent.document). Find ("#objId"). CSS (' height ': ' height '); Window can omit not to write jqueryFourth case: Parent forms accessing properties in an IFRAME
- A, using the Contentwindow method
- document.getElementById (' iframe1 '). onload=function () {
- This.contentWindow.run ();
- }
- b, using iframes[] Frameset Array method
- document.getElementById (' iframe1 '). onload=function () {
- frames["Iframe1"].run ();
- }
Fifth case: Methods and properties that access the parent form in the IFRAME//window can not write
- Window.parent.attributeName; Access attribute AttributeName is the property name in the parent window
- Window.parent.Func (); Access property func () is a method in the parent window
Fifth case:Make IFRAME Adaptive height
- $ (' #iframeId '). Load (function () { //method 1
- var iframeheight = math.min (Iframe.contentWindow.window.document.documentElement.scrollHeight, iframe.contentwindow.window.document.body.scrollheight);
- h=$ (this). Contents (). Height ();
- $ (this). Height (H + ' px ');
- });
-
- $ (' #iframeId '). Load (function () { //method 2
- var iframeheight=$ (this). Contents (). Height ();
- $ (this). Height (iframeheight+ ' px ');
- });
JS Gets the element in the IFRAME and the element that gets the parent in the IFRAME (including when the name and ID do not exist in the IFRAME)