Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda