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

213
Visualizações
Show an Alert if the user write a determinate word in a window. (keyCodes event)

Is that possible with js keyCodes event to show an alert if the user write a determinate word? For example: the user is in homepage, write (without input) "Hello" and appear an alert like "Congratulation, you found the secret word!".

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to bind event listener and keep track of what was typed. Basic idea

const codes = {
  hello: () => console.log('hello there'),
  'funky chicken': () => window.location.href = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
}

function hotKeyListener () {
  let str = '';
  let timeout;
  const msDelay = 400;
  
  window.addEventListener('keydown', function (evt) {
    if (timeout) window.clearTimeout(timeout);
    str += evt.key;
    const action = codes[str];
    if (action) {
      str = '';
      action();
    } else {
      timeout = window.setTimeout(() => str = '', msDelay);
    }
  });
}

hotKeyListener();

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