如何在 amp-iframe 和父级之间共享日期? [英] How to share date between amp-iframe and parent?
问题描述
我想在 iframe 中做一些 POST ajax 请求并将结果返回到我的父页面.
I want to do some POST ajax requests in iframe and return the results to my parent page.
// js inside iframe
//do some queries
var result = 'here will be url for redirect';
w.parent.postMessage({
sentinel: 'amp',
type: 'embed-size',
resultUrl: result, //may be in this way i can pass my data to parent
height: size,
width: size
}, '*');
<amp-iframe width="150"
title="Resizable iframe example from 200x200 to 300x300 "
height="150"
sandbox="allow-scripts"
resizable
frameborder="0"
src="https://localhost:4040/resizable-iframe.html"
class="m1">
<amp-img layout="fill"
src="https://localhost:4040/img.jpg"
placeholder></amp-img>
<div overflow
tabindex="0"
role="button"
class="ampstart-card py1"
aria-label="Show more">Click to show more</div>
</amp-iframe>
也许我可以尝试使用 w.parent.postMessage() 与父页面共享 iframe 中的计算.以及如何从我的放大器页面访问 w.parent.postMessage() 数据.我想使用 resultUrl 将我的放大器页面重定向到下一页.
May be i can try to use w.parent.postMessage() to share my calculations in iframe with parent page. And how to get access to the w.parent.postMessage() data from my amp page. I want use resultUrl to make the redirect on my amp page to next page.
推荐答案
这目前是不可能的(参见 这个问题 在 Github 上进行中).您或许可以使用 amp-form 直接在 AMP 页面中呈现计算结果.这里是一个以这种方式实现的抵押贷款计算器示例.
This is currently not possible (see this issue on Github for work-in-progress). You might be able to use amp-form to render calculation results directly in your AMP page. Here is a sample mortgage calculator implemented this way.
这篇关于如何在 amp-iframe 和父级之间共享日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!