我的 YouTube 视频不会在 iframe 中显示 [英] My YouTube video wont show in iframe

查看:33
本文介绍了我的 YouTube 视频不会在 iframe 中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 HTML 中输入的代码

Here is the code I entered in my HTML

<iframe width="640" height="360" src="https://www.youtube.com/watch?v=ZwKhufmMxko">
</iframe>

视频帧会显示,但实际视频不会加载,甚至不会显示.我试过等待,所以应该不是加载问题.

The video frame will show, but the actual video won't load or even show up. I have tried waiting, so it shouldn't be a loading issue.

我目前也只使用 HTML 和 CSS

I also am currently only using HTML and CSS

关于如何让它发挥作用的任何想法?

Any ideas on how I can get this to work?

推荐答案

YouTube 不允许第三者像这样直接嵌入他们的网站.使用

YouTube doesn't allow 3rd parties to embed their site directly like that. Using

<iframe width="640" height="360" src="https://www.youtube.com/watch?v=ZwKhufmMxko">
</iframe>

将引发错误拒绝在框架中显示https://www.youtube.com/watch?v=ZwKhufmMxko",因为它将X-Frame-Options"设置为SAMEORIGIN". 来表明这一点(你真的应该检查控制台这些东西).

will raise an error Refused to display 'https://www.youtube.com/watch?v=ZwKhufmMxko' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. to indicate this (you should really check the console for these things).

幸运的是,Youtube 提供了嵌入视频"选项,您需要使用该选项才能嵌入视频.

Fortunately Youtube offers the "embed video" option, which you need to use in order to embed videos.

例如,您链接的视频会生成 iframe 代码:

Your linked video for example would produce the iframe code:

<iframe width="560" height="315" src="https://www.youtube.com/embed/ZwKhufmMxko" frameborder="0" allowfullscreen></iframe>

这篇关于我的 YouTube 视频不会在 iframe 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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