youtube - 无法在 'postMessage' : The target origin provided 'DOMWindow' ) does not match the recipient window's origin ('<URL>' ) 上执行 ('<URL>'

标签 youtube youtube-api youtube-javascript-api youtube-iframe-api

我收到此错误: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,
            });
        }
    };
    

    想法?

    最佳答案

    由于您似乎在使用延迟加载,请尝试删除 iframes HTML 属性 loading="lazy" - 为我解决了这个问题。

    关于youtube - 无法在 'postMessage' : The target origin provided 'DOMWindow' ) does not match the recipient window's origin ('<URL>' ) 上执行 ('<URL>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57649870/

    相关文章:

    javascript - YouTube API 开始视频位于

    youtube - 使用JavaScript跟踪Youtube Iframe Player中的社交分享

    ios - 如何强制在 UIWebView 中播放的视频在 iPad 上全屏显示?

    YouTube Chromeless 播放器错误代码

    youtube - 如何使用PHP下载YouTube自动生成的字幕文本(其他人的视频)

    image - 动态创建图像控件,并动态设置图像源

    javascript - youtube视频的播放/暂停按钮

    python - 无法使用 Youtube 数据 API 删除视频

    php - 使用正则表达式从内容过滤youtube链接

    html - IFrame Wmode 中断固定菜单