简体   繁体   中英

Communication from AMP parent frame to page in iframe

I am building a static website using Accelerated Mobile Pages (AMP). Many pages contain iframes using the "amp-iframe" tag. The child pages are not AMP-compliant.

I need a way for a child page to determine when the parent page has finished loading. The normal parent.window.onload can't be used here because the parent pages will often be in different domains (mostly Google's caches) than the child pages.

AMP implements some portion of the postMessage method as a way to communicate between frames (https://www.ampproject.org/docs/reference/components/amp-iframe ), but it is poorly documented and I can't figure out how to reliably pass messages beyond the one example shown at that page.

Any help would be greatly appreciated.

Try downloading some of their free website templates. I think some have forms and a result page which might use iframe.

Example of dynamic interaction with iframe: https://amp.dev/documentation/examples/components/amp-iframe/

I agree their documentation is lousy. Would be so easy if they just posted more example sites and templates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM