Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Javascript) onkeydown doesn't work when press F11 to exit full screen?

I use this code below to count how many times does the user press F11 (on Chrome). When I press F11 to go full screen, the variable countF11 increases 1, but it doesn't change when I press F11 to exit full screen. What is the reason and is there a solution for this?

var countF11 = 0;

document.onkeydown = function (e) {
    if (e.keyCode == 122) {
        countF11++;
        document.getElementById("status").innerHTML = countF11;
    }
}
like image 940
Dylan Harris Avatar asked Dec 17 '25 19:12

Dylan Harris


1 Answers

Chrome intentionally prevents any keyboard event listeners from firing when F11 is pressed when the browser is in "full screen mode." This is to prevent malicious JavaScript from preventing the client from leaving "full screen mode."

Firefox does not have the same limitation; it will work just fine there.

like image 84
Spectric Avatar answered Dec 20 '25 12:12

Spectric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!