简体   繁体   English

html5 视频上的 Firefox onlick 事件

[英]Firefox onlick event on html5 video

In Mozilla Firefox click on html5 video makes it pause/play by default, but not in Chrome or Safari.在 Mozilla Firefox 中,点击 html5 视频使其默认暂停/播放,但在 Chrome 或 Safari 中则不然。 And i want to disable this behavior in FF.我想在 FF 中禁用此行为。 But it seems that FF prevent from bubbling some events on video and i cant catch clicks.但似乎 FF 阻止在视频上冒泡一些事件,我无法捕捉点击。

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

This code will do nothing in FF.这段代码在 FF 中什么也不做。

Any suggestions to solve this?有什么建议可以解决这个问题吗? How can i track click events on html5 video tag in FF?如何在 FF 中跟踪 html5 视频标签上的点击事件?

Should i use some kind of wrappers or...?我应该使用某种包装还是......?

In the last version of FF (64) if you remove the controls attribute of the video element your code works.在 FF (64) 的最新版本中,如果您删除了 video 元素的controls属性,您的代码将起作用。

If you cannot remove controls you may listen, for instance, on the pause event.如果您无法删除控件,您可以监听,例如,暂停事件。 On pause start playing again....暂停时再次开始播放....

 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM