Javascript 是否可以仅从 youtube iframe 嵌入播放器中删除“稍后观看”和“分享”按钮

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

Is it possible to only remove the "watch later" and "share" buttons from youtube iframe embed player

javascripthtmliframeyoutubeyoutube-api

提问by Rohit Kumar

How can I remove the watch later and share buttons from youtube iframe embed player. Using the following embed code for embedding video clips.

我以后如何移除手表并从 youtube iframe 嵌入播放器中共享按钮。使用以下嵌入代码嵌入视频剪辑。

<iframe width="854" height="480" src="https://www.youtube.com/embed/cPVgwz5aN1o" frameborder="0" allowfullscreen></iframe>

Using showinfo=0 removes the full Header which also contains the Video Title.

使用 showinfo=0 删除还包含视频标题的完整标题。

Is it possible to only remove "Watch Later" and "Share" buttons from the header?

是否可以只从标题中删除“稍后观看”和“分享”按钮?

回答by Rohit Kumar

Using YouTube embed's privacy-enhanced mode (youtube-nocookie), it will hide "Watch later" button, but not "Share" button.

使用 YouTube 嵌入的隐私增强模式 (youtube-nocookie),它将隐藏“稍后观看”按钮,但不会隐藏“分享”按钮。

<iframe width="854" height="480" src="https://www.youtube-nocookie.com/embed/cPVgwz5aN1o" frameborder="0" allowfullscreen></iframe>

回答by monkey from Tanzania

This parameter is deprecated and will be ignored after September 25, 2018.

此参数已弃用,2018 年 9 月 25 日之后将被忽略。

showinfo=0 it's not support anymore

showinfo=0 不再支持

回答by b00t

As an example, this is what you're trying to do:

例如,这就是您要执行的操作:

document.getElementsByTagName('iframe')[0].contentWindow.getElementsByClassName('ytp-watch-later-button')[0].style.display = 'none';

But, short answer, there is no simple way to do this, because YouTube is on a different domain:

但是,简短的回答,没有简单的方法可以做到这一点,因为 YouTube 位于不同的域中:

'Not possible from client side . A javascript error will be raised "Error: Permission denied to access property "document"" since the Iframe is not part of your domaine...' https://stackoverflow.com/a/30545122/2488877

'不可能从客户端。将引发 javascript 错误“错误:权限被拒绝访问属性“文档””,因为 Iframe 不是您域的一部分...' https://stackoverflow.com/a/30545122/2488877

Though, you might find an answer suitable to your needs if you're tech-savvy in the answers to the question above.

不过,如果您对上述问题的答案精通技术,则可能会找到适合您需求的答案。

回答by Deendyal Agarwal

Add this line after link

在链接后添加这一行

https://www.youtube.com/embed/c5cHjtspa7M?mode=opaque&amp;rel=0&amp;autohide=1&amp;showinfo=0&amp;wmode=transparent

It will disable the share and watch later option

它将禁用共享和稍后观看选项

回答by RichardB

I don't think it is possible with the iframe method. My reasons for thinking that is:

我认为 iframe 方法是不可能的。我这么想的理由是:

  • It is not an option listed on their parameters page
  • I found this threadwhere a member of their team said it was not possible at the time (2012), and they had no plans to add the ability.
  • 这不是他们的参数页面上列出的选项
  • 我发现了这个帖子,他们团队的一名成员说当时(2012 年)这是不可能的,而且他们没有计划添加该能力。

You could probably achieve something similar by turning showinfo off, and using the other methodsto grab the video title.

您可以通过关闭 showinfo 并使用其他方法获取视频标题来实现类似的效果。

回答by Damian Bennett

showinfo

展会信息

Note: This parameter is deprecated and will be ignored after September 25, 2018.

注意:此参数已弃用,2018 年 9 月 25 日之后将被忽略。

Supported values are 0 and 1.

支持的值为 0 和 1。

Setting the parameter's value to 0 causes the player to not display information like the video title and uploader before the video starts playing.

将该参数的值设置为 0 会导致播放器在视频开始播放之前不显示视频标题和上传者等信息。

If the player is loading a playlist, and you explicitly set the parameter value to 1, then, upon loading, the player will also display thumbnail images for the videos in the playlist.

如果播放器正在加载播放列表,并且您明确将参数值设置为 1,那么在加载时,播放器还将显示播放列表中视频的缩略图。

https://developers.google.com/youtube/player_parameters

https://developers.google.com/youtube/player_parameters

回答by clayRay

The only way to do it is to create a negative margin at the top of a container which has overflowset to hidden. See my CodePen here.

唯一的方法是在overflow设置为的容器顶部创建一个负边距hidden在此处查看我的 CodePen

CSS:

CSS:

.videoWrapper {
  overflow: hidden;
}
@media (min-width: 1500px) {
  .videoWrapper {
    margin-top: -135px;
  }
}
@media (min-width: 1200px) {
  .videoWrapper {
    margin-top: -75px;
  }
}

HTML:

HTML:

<div class="videoWrapper">
  <iframe width="100% src="https://www.youtube.com/embed/cPVgwz5aN1o" frameborder="0" allowfullscreen></iframe>
</div>

But then of course you lose the top of your video. You may also be breaching some of part of YouTube's Terms of Service.

但当然,你失去了视频的顶部。您也可能违反了YouTube 服务条款的某些部分。

Also, this tends to only work well at browser widths above 1200px. Below this the title and top controls take up a much larger percentage of player real estate, so you would lose too much off the top of your video.

此外,这往往只适用于 1200 像素以上的浏览器宽度。在此之下,标题和顶部控件占据播放器空间的更大比例,因此您将失去视频顶部的太多内容。

回答by Martin Nantel

In the url params put the params : showinfo=0.

在 url 参数中输入参数:showinfo=0。

Like this : https://www.youtube.com/embed/youidvideo?autoplay=1&rel=0&showinfo=0

像这样:https: //www.youtube.com/embed/youidvideo?autoplay=1&rel=0&showinfo=0

It will remove share and watch later button!

它将删除共享和稍后观看按钮!