I have created an AMP page and there i have to add an iframe having PDF To display,
Two Question in it:-
How to add iFrame in amp with on:tap event (If a user click on a button the iframe should be add)
Is it Allowed to add non-AMP page as iframe in an amp page.
- How to add iFrame in amp with on:tap event (If a user click on a button the iframe should be add)
Try something like this:
<!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>
Live demo: https://codepen.io/alexandr-kazakov/pen/wvzjqbj
- Is it Allowed to add non-AMP page as iframe in an amp page.
Of course, for example, we can insert a google map or YouTube player into an amp-iframe, although they are not related to AMP.