在amp iframe中加载JavaScript CDN文件

时间:2018-09-07 13:54:12

标签: php amp-html

我想从amp iframe中的cdn加载javascript,但它给出了错误。

  

”未捕获的DOMException:无法从中读取'cookie'属性   '文档':该文档已沙盒化,缺少   'allow-same-origin'标志。”

当我粘贴html文件和iframe代码时,普通javascript在amp iframe中工作正常。在此先感谢您,如果有人可以帮助我解决该错误

html文件名:-testfile.html

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>
    <body>
        <p>Click the button to display an alert box.</p>
        <button onclick="myFunction()">Try it</button>
        <script>
            function myFunction() {
                alert("Hello! I am an alert box!");
            }
        </script>
    </body>
</html>


<amp-iframe width="300" height="200" sandbox="allow-scripts allow-popups allow-modals" layout="responsive" frameborder="0" src="https://test.com/testfile.html">

1 个答案:

答案 0 :(得分:0)

不允许您从同一域插入iframe。它必须来自不同的域。尝试添加来自其他域的iframe。 同样,元素必须位于视口的前75%之外或顶部的600px(以较小者为准)。考虑到这2点,您将可以在AMP上看到iframe。看一下随附的示例代码...并相应地更改amp-iframe src。

SELECT 
REGEXP_SUBSTR(REGEXP_SUBSTR('1-2-3','([0-9] *- *[0-9] *- *[0-9])',1, 1, 'i'),'([0-9] *- *[0-9] *- *[0-9])',1,1,'i') AS Tmp,
REGEXP_SUBSTR(tmp,'(^[0-9])',1,1,'i') ||'-' ||  REGEXP_SUBSTR(tmp,'([0-9]$)',1,1,'i') AS final_exp;