AMP IFrame 在 AMP LightBox 中不起作用



示例:-

<amp-lightbox id="my-lightbox" layout="nodisplay">
<div class="lightbox" on="tap:my-lightbox.close" role="button" tabindex="0">
<amp-iframe width="350" height="300" layout="fixed" sandbox="allow-scripts allow-same-origin allow-popups" frameborder="0" src="https://ampbyexample.com/"></amp-iframe>
</div>
</amp-lightbox>
<button class="ampstart-btn caps m2" on="tap:my-lightbox" role="button" tabindex="0">Open Iframe in Lightbox</button>

我还尝试从顶部操纵 iFrame 75% 或 600px 的位置,但它也不起作用。

AMPiFrame 包含 Jquery UI 日历,我们希望使用它来获取用户在我们的 AMP 页面中选择的送达日期。

是否可以在 AMP iFrame 中获取和传递该值?

如果您在显示 iframe 时遇到问题,请向 iframe 元素添加占位符图像。这将允许您规避 75%/600 像素的限制。您可以添加如下所示的占位符:

<amp-iframe width="350" height="300" layout="fixed" 
sandbox="allow-scripts allow-same-origin allow-popups" frameborder="0" 
src="https://ampbyexample.com/">
<amp-img layout="fill"
src="https://placekitten.com/g/300/300"
placeholder></amp-img>
</amp-iframe>

已更新(添加了有关与 iframe 父级共享数据的句子(

如果您尝试将数据从 amp-iframe 发送到父级,这将不起作用。此处解释了该限制: https://github.com/ampproject/amphtml/blob/master/spec/amp-iframe-origin-policy.md

AMP iframe将无法正常工作,因为 amp-iframe 可能不会显示在文档顶部附近(使用占位符的 iframe 除外,如下所述(。滚动到顶部时,iframe 必须距离顶部 600 像素,或者不在视口的前 75% 内,以较小者为准。

当 amp-iframe 具有占位符元素时,可以在文档顶部显示 amp-iframe,如下例所示。 amp-iframe 必须包含一个具有占位符属性的元素(例如 amp-img 元素(,该元素将呈现为占位符,直到 iframe 准备好显示。 欲了解更多信息,请点击链接。

您正在使用位置固定且在视口前 75% 内的灯箱。

在 AMP 网页中使用日历的另一种方法是 AMP 日期选择器。欲了解更多信息,请点击链接。

最新更新