Youtube“阻止了一个带有来源的框架"http://www.youtube.com“从访问具有原点的帧"即使使用相同的协议 [英] Youtube "Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin" even if the same protocol is used

查看:27
本文介绍了Youtube“阻止了一个带有来源的框架"http://www.youtube.com“从访问具有原点的帧"即使使用相同的协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌入 Youtube 播放列表时出现此错误:

When embedding a Youtube playlist I am getting this error:

阻止了来源为http://www.youtube.com"的框架访问来源为http://www.mydomain.com"的框架.协议、域和端口必须匹配.

我没有在任何地方混合 HTTP 和 HTTPS,所以我不知道为什么我首先会收到这个错误.

I am not mixing HTTP with HTTPS anywhere, so I don't know why I am getting this error in the first place.

我注意到最近 Youtube 嵌入的播放列表没有显示第一个视频的嵌入图像,只是显示一个带有全部播放"按钮的黑屏,我想知道这是否是由上述错误引起的.

I have noticed that recently the Youtube embedded playlist is not displaying the embed image of the first video and just displaying a black screen with a 'Play All' button, and I am wondering if this is being caused by the above error.

推荐答案

显然 chrome 给出的错误是一个 bug.为了解决全部播放"按钮问题的黑屏问题,我使用了 Javascript API(而不是 iframe),如下所示:

Apparently it seems that the error given by chrome is a bug. In order to solve the black screen with 'Play All' button issue I used the Javascript API (instead of the iframe), like this:

<!DOCTYPE html>
<html>
  <body>
    <div id="player"></div>
    <script>
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: '',
          events: {
            'onReady': onPlayerReady 
          }
        });
      }
      function onPlayerReady(event) {
        player.cuePlaylist({'listType':'playlist','list':'PLE2714DC8F2BA092D'});
      }
    </script>
  </body>
</html>

感谢@jlmcdonald 的回答,如下所示:Youtube 嵌入的播放列表显示播放按钮而不是第一个视频

Thanks to @jlmcdonald for the answer, as indicated here: Youtube embedded playlist diplays playall button instead of the first video

这篇关于Youtube“阻止了一个带有来源的框架"http://www.youtube.com“从访问具有原点的帧"即使使用相同的协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆