Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Triiger event when pressing ESC from Full Screen

I have a <div> element that is hidden. Following a click event the element opens in fullscreen.

When a user clicks ESC to exit fullscreen, I would like the <div> to automatically return to hidden in the regular view.

The following code allows ESC to hide the <div> in the normal view but is ignored when in fullscreen mode. This means it takes 2 clicks of ESC to hide the <div>. The first click exits fullscreen as per the normal browser functionality and returns to normal view with the <div> visible. A second click of ESC is then required to trigger the <div> to be hidden

$(document).keyup(function(e) {
if (e.keyCode === 27) { 
    $('#Box').hide();
}})

Is it possible to have my code incorporated into the initial browser response to the ESC key being pressed so the element is never visible in regular view? Or is there another workaround?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can listen for fullscreenchange events and then run your code when that event fires and it's a change from fullscreen -> normal.

For example:

$(document).on('fullscreenchange', function(e) {
    if (document.fullscreenElement) {
        // Entered fullscreen
    } else {
        // Left fullscreen; run your code here
        $('#Box').hide();
    }
});
about 4 years ago · Juan Pablo Isaza Report

0

I managed to solve my own question by extending ps4star's solution. To allow for cross browser compatibility I added moz and webkit variations but possibly still need to bug test and modify to cover as many browsers as possible.

function isFullScreen() {
$('#Box').show();
}

function notFullScreen() {
$('#Box').hide();
}

document.addEventListener("fullscreenchange", function () {
if (document.fullscreen) {
    isFullScreen();
} else {
    notFullScreen();
}
}, false);

document.addEventListener("mozfullscreenchange", function () {
if (document.mozFullScreen) {
    isFullScreen();
} else {
    notFullScreen();
}
}, false);

document.addEventListener("webkitfullscreenchange", function () {
if (document.webkitIsFullScreen) {
    isFullScreen();
} else {
    notFullScreen();
}
}, false);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!