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

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

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 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