AMP:<amp-iframe> 的起源不能等于容器 [英] AMP: Origin of <amp-iframe> must not be equal to container
问题描述
我想在我的第一个 AMP 项目中解决这个问题,
I want to solve this problem in my first AMP project,
这是我遇到的问题:
error.js:58:
error.js:58:
Origin of <amp-iframe> must not be equal to container
这是我的 index.html 中的 amp-iframe 代码:
This is my amp-iframe code in my index.html:
<amp-iframe
width=100
height=100
layout="nodisplay"
sandbox="allow-same-origin allow-forms allow-scripts"
src="https://www.example.com/scripts/app.js">
</amp-iframe>
当我浏览控制台选项卡时,这就是我所拥有的:
when I navigate the console tab, this is what I have:
Powered by AMP ⚡ HTML – Version 1462999126709
AMP validation successful.
我使用
来使用外部 javascript,我的 custom.js
I used <amp-iframe>
to use external javascript, my custom.js
推荐答案
问题是您正在尝试对与 AMP 同源的内容进行 amp-iframe.出于安全原因,这是被禁止的(主要与同源策略在 iframe 中使用合成源的方式有关).
The problem is that you're trying to amp-iframe content that's on the same origin as the AMP. That's forbidden for security reasons (mostly to do with the way the same-origin policy uses synthetic origins inside iframes).
解决方法是确保外部 JS 从不同的来源提供给您的 AMP.因此,如果您的 AMP 在 example.com 上,那么您应该提供来自 SOMEOTHERORIGIN.example.com 的 iframe JS
The fix is to make sure that external JS is served from a different origin to your AMP. So if your AMPs are on example.com then you should serve the iframed JS from SOMEOTHERORIGIN.example.com
这篇关于AMP:<amp-iframe> 的起源不能等于容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!