The cross-domain iframe height of the pit daddy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.