If a child page cross-domain problem is encountered, it can be achieved by HTML5 PostMessage, but only if the child page needs to proactively send information to the parent page. Here is the Sub-page section:
<!DOCTYPE HTML> <Head> </Head> <Bodyonload= "Parent.postmessage (document.body.scrollHeight, ' http://target.domain.com ');"> <H3>Got post?</H3> <P>Lots of stuff here which'll be inside the IFRAME.</P> </Body> </HTML>
Gets the information passed to the child page in the parent page, and adjusts the height of the iframe.
<Scripttype= "Text/javascript"> functionresizecrossdomainiframe (ID, other_domain) {variframe=document.getElementById (ID); Window.addeventlistener ('message', function(event) {if(Event.origin!==Other_domain)return; //Only accept messages from the specified domain if(IsNaN (event.data))return; //Only accept something which can be parsed as a number varHeight=parseint (event.data)+ +; //add some extra height to avoid scrollbarIframe.height=Height+ "px"; }, false); } </Script> <iframesrc= ' abc.html 'ID= "Frm1"onload= "Resizecrossdomainiframe (' Frm1 ', ' http://example.com ');">
Highly adaptive under the same domain
<iframesrc= "http://demo.cn/downloadapp/demo.html"frameborder= "0"width= "100%"style= "Opacity:1"Height=100%ID= "Iframepage"name= "Iframepage"OnLoad= "Iframeheight ()"></iframe><Script> functioniframeheight () {varIFM=document.getElementById ("Iframepage"); varSubweb=Document.frames?document.frames["Iframepage"].document:ifm.contentdocument; if(IFM!= NULL &&Subweb!= NULL) {Ifm.height=SubWeb.body.scrollHeight; } }</Script>
The cross-domain iframe height of the pit daddy