Given is an HTML5
video element. A button should change this video element into fullscreen, or end the fullscreen.
I have already written a JavaScript
function. This works fine in Firefox
. Unfortunately, the function does not work in Google Chrome.
function toggleFullScreen() {
var player = document.querySelector('#playerContainer');
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (player.mozRequestFullScreen) {
player.mozRequestFullScreen();
}
else {
player.webkitRequestFullScreen();
}
} else {
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
}
While everything works fine in Firefox
, in Chrome
, the window is positioned only in the middle of the full-screen window. Also, Chrome can not quit the fullscreen.
I used Firefox Quantum 61.0.1
and Google Chrome 68.0
.