【发布时间】:2019-12-30 04:05:45
【问题描述】:
我收到此错误:Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('<URL>') does not match the recipient window's origin ('<URL>').
我的页面按我希望的方式运行(我没有注意到任何不良行为),但我从不喜欢忽略控制台中的错误,尤其是当我什至不了解根本原因时。
我的问题不是重复的,因为我已经研究了所有这些问题,但没有一个答案有效:
- Failed to execute 'postMessage' on 'DOMWindow': https://www.youtube.com !== http://localhost:9000
- Failed to execute 'postMessage' on 'DOMWindow': The target origin provided does not match the recipient window's origin ('null')
- Youtube API - Failed to execute 'postMessage' on 'DOMWindow'
- YouTube API and cross origin requests
- YouTube iFrame Player API failed to execute postMessage on DOMWindow
- Failed to execute 'postMessage' on 'DOMWindow': target/origin mismatch http vs https
我已经在使用https。
我已经尝试将playerVars 设置为{origin: window.location.origin}。
我已经尝试过设置host。
我已经尝试过更改 iframe 的可见性。
等等。
var playerVars = {origin: window.location.origin};//https://stackoverflow.com/a/50518247/470749
window.onYouTubeIframeAPIReady = function () {
for (var i = 0; i < youtube.length; i++) {
var youtubeLazyEl = youtube[i];
var videoId = youtubeLazyEl.dataset.v;
players[videoId] = new YT.Player(videoId, {
videoId: videoId,
//host: 'https://www.youtube.com', //https://stackoverflow.com/a/47914456/470749
//playerVars: playerVars,
});
}
};
想法?
【问题讨论】:
-
您找到解决方案了吗?在尝试了其他线程中建议的所有解决方案后,我仍然遇到此错误。
-
@Sarcadass 不幸的是没有。如果您找到了,请在此处发布!
标签: youtube youtube-api youtube-javascript-api youtube-iframe-api