Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda