Firefox onlick event on html5 video



在Mozilla Firefox中,单击html5视频可以默认暂停/播放,但在Chrome或Safari中则不会。我想在FF中禁用此行为。但似乎FF阻止了视频上的一些事件冒泡,我无法捕捉点击。

window.addEventListener("click", function(e){
    if (e.target && e.target.matches('.html5video')) { 
        console.log('click');
    }       
});

此代码在 FF 中不执行任何操作。

有什么建议可以解决这个问题吗?如何在FF中跟踪html5视频标签上的点击事件?

我应该使用某种包装器还是...?

在最新版本的 FF (64) 中,如果删除视频元素的控件属性,则代码将正常工作。

如果无法删除控件,则可以侦听,例如,暂停事件。暂停时再次开始播放。

document.querySelector('.html5video').addEventListener('pause', function(e) {
   // don't pause....
   this.play();
})
<video class="html5video" width="400" controls>
    <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
    <source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
</video>

最新更新