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

265
Views
Cómo salir de la pantalla completa presionando ESC o alternando el botón de pantalla completa

En el siguiente fragmento, cuando se presiona el botón "Hacer una pantalla completa", el iFrame ingresa al modo de pantalla completa. Estoy buscando una solución para salir del modo de pantalla completa presionando "ESC" o presionando "Hacer botón de pantalla completa" nuevamente.

 <button onclick="makeFullscreen('game');">[Make a fullscreen]</button>
 function makeFullscreen(id){ var el = document.getElementById(id); el.style = "position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;" }

Totalmente trabajando

 const fullscreenStyle = "position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:99999;" const normalStyle = "width:1000px;height:700px;border:0;" function enterFullScreen(el) { el.style = fullscreenStyle; document.querySelector('.button1').style = 'position:absolute;top:0;right:0;z-index:999999;'; } function exitFullScreen(el) { el.style = normalStyle; document.querySelector('.button1').style = 'position:absolute;top:auto;right:auto;'; } function toggleFullScreen() { var el = document.getElementById("game"); if (el.style.position === "fixed") { exitFullScreen(el); } else { enterFullScreen(el); } } document.addEventListener("keydown", function(e) { if (e.key === "Escape") { var el = document.getElementById("game"); exitFullScreen(el); } }, false);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Dado que laAPI de pantalla completa está fuera, otra solución puede ser que, en lugar de vincular la lógica Make a Fullscreen completa al botón, vincule la lógica para alternar la pantalla completa. Para eso :

  1. Almacene CSS de pantalla completa y modo normal en 2 variables separadas
  2. Crear 2 funciones, enterFullscreen en pantalla completa y exitFullScreen de pantalla completa
  3. Cree una tercera función toggleFullScreen que verifique el modo y haga lo siguiente:
  • Si el modo de pantalla completa está activado, llame a exitFullscreen
  • De lo contrario, llame a enterFullScreen

Para implementar la salida al presionar ESC

  1. Agregue un detector de eventos para eventos keydown
  2. Cuando se activa el evento, verifique la key en el evento.
  3. Si la key coincide con Escape , llame a exitFullScreen

La siguiente solución hace lo mismo.

 <!DOCTYPE html> <html lang="en"> <body> <iframe id="game" style="width:1000px;height:700px;border:0;" allowfullscreen="true" msallowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" sandbox="allow-same-origin allow-popups allow-scripts allow-pointer-lock allow-orientation-lock allow-popups" src="https://randomurl.com/"> </iframe> <button onclick="toggleFullScreen('game');"> [Toggle fullscreen] </button> </body> <script type="text/javascript"> const fullscreenStyle = "position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;" const normalStyle = "width:1000px;height:700px;border:0;" function enterFullScreen(el) { el.style = fullscreenStyle; } function exitFullScreen(el) { el.style = normalStyle; } function toggleFullScreen() { var el = document.getElementById("game"); if (el.style.position === "fixed") { exitFullScreen(el); } else { enterFullScreen(el); } } document.addEventListener("keydown", function(e) { if (e.key === "Escape") { var el = document.getElementById("game"); exitFullScreen(el); } }, false); </script> </html>
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!