How to prevent event bubbling when clicking on HTML5 video controls in Firefox
What you've got there is invalid markup, the HTML5 spec clearly states that
The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).
and the video navigation is in fact interactive content containing buttons.
For some reason clicking the controls in Chrome does not trigger the anchor, while in Firefox it does.
This is dependant on how the browser constructs the controls with the Shadow DOM, and as the markup is invalid and there is no real standard for this, it's anyone's guess.
What you should have done is to remove the anchor and use javascript to redirect when the video is clicked, something like this
$('#testid').on('click', function() {
var win = window.open('http://www.google.com', '_blank');
win.focus();
});
That would have given you valid markup as you could just remove the wrapping anchor, but it doesn't solve the problem with not redirecting when clicking the controls either, it's exactly the same, as the controls are still inside the video and triggers the click handler in Firefox, but not in Chrome.
In webkit the controls could potentially have been targeted somehow with the -webkit-media-controls
pseudo class, however Firefox doesn't seem to have any such pseudo class, so that won't work either.
What you're left with is relying on the fact that the controls seem to always be at the bottom, and they are around 30 pixels high, so you can just overlay the anchor on top of the video and leave out a little part of the bottom.
This will work in all browsers, and you'll have valid markup.
<video controls="" muted="" autoplay preload="auto" id="testid" width="500">
<!-- stuff -->
</video>
<a href="http://www.google.com" class="overlay" target="_blank"></a>
To make sure the anchor is placed correctly and has the correct size, a little javascript can be used
$('.overlay').each(function() {
var vid = $(this).prev('video');
$(this).css({
position : 'fixed',
top : vid.offset().top + 'px',
left : vid.offset().left + 'px',
width : vid.width() + 'px',
height : (vid.height() - 30) + 'px',
});
});
FIDDLE