且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

amp-iframe 内的 amp 页面上的 Disqus

更新时间:2023-12-03 09:11:10

它似乎是此错误的一个实例:https://code.google.com/p/chromium/issues/detail?id=541221

It appears to be an instance of this bug: https://code.google.com/p/chromium/issues/detail?id=541221

如果使用沙箱属性,标准 iframe 也会发生同样的事情.

The same thing does happen with a standard iframe if using the sandbox attribute.

allow-same-origin 添加到您的沙箱定义中似乎可以解决此问题.我注意到它现在在 Firefox 中也是一样的,尽管该错误中的评论(尽管 Firefox 没有明确列出错误)它在那里工作.所以也许这就是它应该如何工作?不能说我对沙箱属性的了解足以告诉您这一点.

Adding allow-same-origin to your sandbox definition seems to fix it. I notice it's the same in Firefox now too despite the comment in that bug (though firefox doesn't list the error as explicitly) that it works there. So maybe this is how it's supposed to work? Can't say I know enough about the sandbox attribute to tell you that.

但是,顺便说一句,我不确定这是否是个好主意.您将拥有此页面的非 AMP 版本吗?就我个人而言,我不认为仅 AMP 页面的情况,因为我认为这会限制您,因为 1) 在 AMP 中并非一切皆有可能,2) 某些客户端不会加载它(例如,如果没有 javascript,或者不了解 AMP),所以我也更喜欢有一个真正的 HTML 页面.但是,如果您确实有单独的 HTML 和 AMP 页面,那么它们将分别跟踪评论(除非您将非 AMP 页面加载到此 iframe 中并以某种方式隐藏除评论之外的所有内容 - 但这似乎完全是浪费!).

However, as an aside, I'm not sure this is such a great idea anyway. Will you be having a non-AMP version of this page? Personally I don't see the case for an AMP only page as I think this limits you since 1) not everything is possible in AMP and 2) some clients won't load this (e.g. if no javascript, or doesn't understand AMP), so I prefer to have a real HTML page too. However if you do have separate HTML and AMP pages then they will track comments separately (unless you load your non-AMP page into this iframe and somehow hide everything but the comments - but that seems a complete waste!).

因此,我目前的实现方式是向我的 AMP 页面添加一个单击此处查看评论"链接,将它们带到完整页面 - 带有评论.不是一个很好的解决方案,但至少可以将评论放在一起.

So the way I implement this at present is to add a "click here to view comments" link to my AMP pages which take them to the full page - with comments. Not a great solution but at least keeps comments together.