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

168
Vistas
Javascript Keydown Not Triggering

I need help with getting the keydown of up arrow to trigger. I dont really understand what the problem with this is, most likely my messy formatting, but the keydown just doesn't trigger.

<script>
  window.addEventListener('keyup', (event) => {
    if (event.key == 'ArrowUp') {
        close();
    window.open("https://bsd.instructure.com/?login_success=1");
    }
});
</script>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Check out the window.close() and window.open() API.

JavaScript cannot open windows if the browser blocks them. I tried your code and it says:
"Firefox prevented this site from opening a pop-up window. [Options]".

You can only open windows user-generated (e.g. button / link click).
Your event is working fine, but the browser is preventing the pop-up window.

window.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    window.close(); // Blocked for certain standards
    window.open("https://bsd.instructure.com/?login_success=1"); // Blocked in the user's preferences
  }
});

I also recommend you use document events instead of window:

document.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    // Action here
  }
});

You can use the window location property to navigate to pages.

document.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    window.close();
    window.location.replace("https://bsd.instructure.com/?login_success=1");
  }
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

Only for the sake of completeness. as @Mike 'Pomax' Kamermans already answered the question correctly. bind the document object to the event instead of the window object.

document.addEventListener('keyup', (event) => {     
    if (event.key == 'ArrowUp') {
        console.log('Arrow UP');
        close();
    }
});

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