Html 我的 YouTube 视频不会在 iframe 中显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36337086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
My YouTube video wont show in iframe
提问by jdavid
Here is the code I entered in my HTML
这是我在 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.
视频帧将显示,但实际视频不会加载甚至显示。我试过等待,所以它不应该是加载问题。
I also am currently only using HTML and CSS
我目前也只使用 HTML 和 CSS
Any ideas on how I can get this to work?
关于如何让它发挥作用的任何想法?
回答by apokryfos
YouTube doesn't allow 3rd parties to embed their site directly like that. Using
YouTube 不允许第 3 方像这样直接嵌入他们的网站。使用
<iframe width="640" height="360" src="https://www.youtube.com/watch?v=ZwKhufmMxko">
</iframe>
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).
将引发一个错误Refused to display 'https://www.youtube.com/watch?v=ZwKhufmMxko' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
来表明这一点(你真的应该检查控制台这些事情)。
Fortunately Youtube offers the "embed video" option, which you need to use in order to embed videos.
幸运的是,Youtube 提供了“嵌入视频”选项,您需要使用它来嵌入视频。
Your linked video for example would produce the iframe code:
例如,您链接的视频将生成 iframe 代码:
<iframe width="560" height="315" src="https://www.youtube.com/embed/ZwKhufmMxko" frameborder="0" allowfullscreen></iframe>
回答by user3467534
Change "watch?v=" to "embed/"
将“watch?v=”改为“embed/”
The easiest way to get the correct link is to right-click on the YouTube video and select "copy embed code".
获得正确链接的最简单方法是右键单击 YouTube 视频并选择“复制嵌入代码”。
<iframe width="854" height="480" src="https://www.youtube.com/embed/ZwKhufmMxko" frameborder="0" allowfullscreen></iframe>