【发布时间】:2022-10-19 12:18:07
【问题描述】:
在 PrestaShop 中,我使用了一个嵌入 YouTube 视频的模块,例如:
<iframe width="560" height="315" frameborder="0" iv_load_policy="3" fs="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" data-src="https://youtube.com/embed/VIDEO_ID?rel=0&controls=0&showinfo=0&modestbranding=1"></iframe>
一切似乎都正常/视频正在播放 - 但在浏览器控制台中我看到以下错误:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://youtube.com') does not match the recipient window's origin ('https://OUR_DOMAIN').
在我花了很多时间在 SOO 上搜索和阅读所有类似问题之后,这个问题与 CORS 或类似问题无关。大多数报告此问题的人声称这是由于 YouTube 视频的加载方式,包括。参数等...我尝试了多种方法-但我没有成功消除此错误。我希望你们有办法在 2022 年解决这个问题。
【问题讨论】:
-
在副本中,this answer 看起来最适合您的具体情况。
-
我的英雄!谢谢你救了我更多的头痛! :) 创建一个答案我的朋友!
-
Gregory Magarshak 已经写下了答案。点赞!
标签: javascript youtube postmessage youtube-iframe-api