如何在Firefox中禁用视频的单击和双击控件

How to disable click and double click controls for a video in Firefox?

本文关键字:单击 双击 控件 视频 Firefox      更新时间:2023-09-26

我有一个视频(<video id="video" controls src="foo.webm"></video>),用这个视频我有一组onclickondblclick。在Chrome上,这很好,但在Firefox上,他们的"点击切换播放状态"answers"双击全屏"会干扰我设置的代码。有没有办法从Javascript中禁用这些"功能"?

我尝试过event.preventDefault()return false,但它们对ondblclick根本不起作用,部分对onclick起作用。部分工作,这意味着他们完全禁用了所有控制,你甚至不能点击视频左下角的播放/暂停按钮来播放/暂停。

HTML

<div class="videocontainer">
    <div class="close">X</div>
    <video id="video" controls src="foo.webm"></video>
</div>

JavaScript

var video = document.getElementById('videocontainer');
video.onclick = function(ev) {
    ev.preventDefault(); //Disables all click events, including play/pause button
    if (ev.target.getAttribute('class') === close) closeVideo(); //if you clicked the close button it will close the video
    return false;        //Disables all click events, including play/pause button
};
video.ondblclick = function(ev) {
    ev.preventDefault(); //doesn't change anything
    if (ev.target.nodeName.toLowerCase() === 'video') popoutVideo();  //if you double clicked the video itself it will make the video fixed at the bottom right of the screen
    return false;        //doesn't change anything
};

我刚刚添加了controlsList="nofullscreen";属性<video id="vd" src="video.mp4" disablePictureInPicture controls controlsList="nofullscreen"></video>