嵌入 Youtube 代码在 HTML 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51424578/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 15:43:21  来源:igfitidea点击:

Embed Youtube code is not working in HTML

html

提问by Pearl Oyun

I am trying to use embed youtube code in HTML but when I press play button it say "This video is unavailable". I am using the following HTML code for it:

我正在尝试在 HTML 中使用嵌入 youtube 代码,但是当我按下播放按钮时,它说“此视频不可用”。我正在使用以下 HTML 代码:

<iframe width="560" height="315" src="https://www.youtube.com/embed/JfJYHfrOGgQ" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Can anyone help me out with this? I have tried other embed youtube videos too, still says same thing. I am using Chrome.

谁能帮我解决这个问题?我也尝试过其他嵌入 youtube 视频,仍然说同样的话。我正在使用 Chrome。

enter image description here

在此处输入图片说明

回答by Ahmed Maher

I had the same issue recently and it had nothing to do with video owners embedding settings. Apparently YouTube forbids embedding some videos in a localhost environment without a public domain, but your video can be embedded with no issue whatsoever through a public domain/subdomain: Replace the src value in the JSFiddle from @PStarczewski's answer with your video link and it will work properly.

我最近遇到了同样的问题,它与视频所有者嵌入设置无关。显然,YouTube 禁止在没有公共域的本地主机环境中嵌入一些视频,但是您的视频可以通过公共域/子域毫无问题地嵌入:将 @PStarczewski 回答中的 JSFiddle 中的 src 值替换为您的视频链接,它将好好工作。

回答by c1u31355

For me this was caused by a referrer policy "no-referrer" on my site. Youtube seems to block embedding when no-referrer is set.

对我来说,这是由我网站上的推荐人政策“无推荐人”引起的。Youtube 似乎在设置 no-referrer 时阻止嵌入。

Hope to save someone from wasting time with this crap.

希望拯救某人免于浪费时间。

回答by PStarczewski

On YouTube there is so called "embed settings" where owner of the video can decide whether or not to allow for it.

在 YouTube 上有所谓的“嵌入设置”,视频所有者可以在其中决定是否允许它。

Here is an example: JSFiddle

这是一个例子: JSFiddle

<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLsyvDWwjkTqtOmqAiTzzfHspTAztB-udL" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/JfJYHfrOGgQ" frameborder="0" gesture="media" allow="autoplay; encrypted-media" allowfullscreen></iframe>

And here you can find more details about this: YouTube Restrict embedding

在这里您可以找到有关此的更多详细信息:YouTube 限制嵌入

回答by Sourabh Chavan

I just came to know It depends on Owner. If owner enables the embedded settings then you can add this links to your Html. just for example 1st add famous videos (which has more than 1M likes i.e songs) then add any video which has like 1k like.

我才知道这取决于所有者。如果所有者启用了嵌入设置,那么您可以将此链接添加到您的 Html。例如,第一次添加著名视频(喜欢的视频超过 100 万,即歌曲),然后添加任何喜欢 1k 的视频。