AMP-iframe中的动态src

AMP-iframe中的动态src,iframe,amp-html,Iframe,Amp Html,我在一个嵌入其他网站的应用程序中工作,其中一些网站使用AMP。我目前正在使用amp iframe,我需要iframe当前嵌入的网站url,以便我的应用程序正常工作。我正试图通过params传递它,以便在我的应用程序中使用它 我一直在尝试使用amp脚本获取location.href(或location.origin+location.pathname),并设置amp状态以动态更改Iframe src。目前不工作 HTML: 有没有办法解决这个问题 谢谢 不幸的是,您在AMP脚本中可以访问的AMP对

我在一个嵌入其他网站的应用程序中工作,其中一些网站使用AMP。我目前正在使用amp iframe,我需要iframe当前嵌入的网站url,以便我的应用程序正常工作。我正试图通过params传递它,以便在我的应用程序中使用它

我一直在尝试使用amp脚本获取location.href(或location.origin+location.pathname),并设置amp状态以动态更改Iframe src。目前不工作

HTML:

有没有办法解决这个问题


谢谢

不幸的是,您在
AMP脚本
中可以访问的
AMP
对象与工作者外部的
AMP
对象不同

AMP.win
未定义的
。我甚至不认为
window.AMP.setState==“function”
会起作用

有关如何在
AMP脚本
中使用
AMP.setState
的示例,请参见

我们确实需要有人介绍对
位置
对象的支持。和你一样,评论也会有所帮助。我们真正需要的是有时间贡献代码的人
<amp-script layout="container" src="https://cdn.website.com/script.js">
       <amp-iframe height="150" resizable sandbox="allow-scripts allow-same-origin allow-popups allow-forms" frameborder="0" src="https://website.com/dev/html" [src]="dynamicUrl">
          <div overflow tabindex="0"></div>
      </amp-iframe>
</amp-script>
function checkForAmp(method) {
  if (window.AMP && typeof window.AMP.setState === "function") {
    method();
  } else {
    setTimeout(function () {
      checkForAmp(method);
    }, 50);
  }
}

function getUrlAndUpdateWidget() {
  const url = `https://website.com/dev/html?dynamic-url=${
    window.AMP.win.location.origin + window.AMP.win.location.pathname
  }`;
  window.AMP.setState({ dynamicUrl: url });
}

checkForAmp(getUrlAndUpdateWidget);