Javascript 在 YouTube 上点击时禁用 HTML5 <video> 的播放/暂停/全屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28389347/
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
Disable play/pause/full screen for HTML5 <video> on click for YouTube
提问by jianweichuah
Is there a way for us to disable the "play/pause/full screen on click" functionality for a HTML5 video through javascript and later put it back when we need it again?
有没有办法让我们通过javascript禁用HTML5视频的“播放/暂停/点击全屏”功能,然后在我们再次需要时将其放回去?
采纳答案by jianweichuah
I'm not sure why <video>doesn't honor event.preventDefault();
我不知道为什么<video>不尊重event.preventDefault();
The way I go around this is pretty hacky. I just override the click and dblclick events of the parent div to solve my problem since I only want to prevent pause/play/full screen.
我解决这个问题的方式非常笨拙。我只是覆盖父 div 的 click 和 dblclick 事件来解决我的问题,因为我只想防止暂停/播放/全屏。
回答by Dzhambazov
I don't know if you can disable them but you can remove them using css.
我不知道您是否可以禁用它们,但您可以使用 css 删除它们。
video::-webkit-media-controls-fullscreen-button, video::-webkit-media-controls-play-button, video::-webkit-media-controls-pausebutton {
display: none;
}
I hope this helps.
我希望这有帮助。
回答by meLlamoRoberto
The below line can solve the purpose.
下面的行可以解决目的。
video.removeAttribute('controls');

