我想在iframe中执行一些POST ajax请求,并将结果返回给我的父页面。
// 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中与父页面共享我的计算结果。以及如何从我的amp页面访问w.parent.postMessage()数据。我想使用resultUrl使我的放大器页面重定向到下一页。
发布于 2017-10-11 16:29:53
这目前是不可能的(参见Github上的this issue了解正在进行的工作)。您可以使用amp-form直接在AMP页面中呈现计算结果。Here是一个以这种方式实现的抵押贷款计算器示例。
https://stackoverflow.com/questions/46663172
复制相似问题