on:点击在AMP中添加iframe



我创建了一个AMP页面,在那里我必须添加一个具有PDF的iframe来显示,

其中的两个问题:-

  1. 如何在带有on:tap事件的放大器中添加iFrame(如果用户单击按钮,则应添加iFrame(

  2. 是否允许将非AMP页面添加为AMP页面中的iframe。

  1. 如何在带有on:tap事件的amp中添加iFrame(如果用户单击按钮,则应添加iFrame(

试试这样的东西:

<!DOCTYPE html>
<html ⚡>
<head>
<meta charset="utf-8" />
<title>My AMP Page</title>
<link rel="canonical" href="self.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" />
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<style amp-boilerplate>
body {
-webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
animation: -amp-start 8s steps(1, end) 0s 1 normal both;
}
@-webkit-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-moz-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-ms-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-o-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
</style>
<noscript>
<style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style>
</noscript>
<style amp-custom>
.wrapper {
max-width: 700px;
margin: 0 auto;
}
</style>
</head>
<body>
<main class="wrapper">
<h1>My AMP Tap iframe</h1>
<button type="button" on="tap:AMP.setState({ myIframeUrl: 'https://docs.google.com/gview?url=http%3A%2F%2Fwww.pdf995.com%2Fsamples%2Fpdf.pdf&embedded=true' })" [hidden]="myIframeUrl">Load my PDF iframe</button>
<amp-iframe sandbox="allow-scripts allow-same-origin" src="https://google.com/" width="1" height="1" layout="responsive" [src]="myIframeUrl" [hidden]="!myIframeUrl" hidden>
<div placeholder>PDF coming</div>
</amp-iframe>
</main>
</body>
</html>

现场演示:https://codepen.io/alexandr-kazakov/pen/wvzjqbj


  1. 是否允许将非AMP页面添加为AMP页面中的iframe

当然,例如,我们可以将谷歌地图或YouTube播放器插入到amp iframe中,尽管它们与amp无关。

最新更新