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

88
Vistas
why not working document.body.style.backgroundColor?

I'm working on a logic that turns the screen black when I press the print screen shot key. I'm changed background color but not working. The console detected a change in value.

What's wrong?

I use typescript and next.js

function App({ Component, pageProps }: AppProps) {
  const [value, setValue] = useState(false);

  useEffect(()=> {
    const keyUpListener = (e:KeyboardEvent) => {
      if (e.key === 'PrintScreen' || e.key === 'F13') {
        alert('test');
        document.body.style.zIndex = '999999';
        document.body.style.backgroundColor = 'black';
        setValue(v => !v);
      }
    }

    document.addEventListener('keyup', keyUpListener);

    return () => document.removeEventListener('keyup', keyUpListener);
  }, []);

  return <>
    <Component {...pageProps} />
  </>;
}

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

0

Maybe try changing the keyup event to keydown to track the key press before it is triggered.

Also remember to unbind your event to avoid memory leaks.

useEffect(() => {
document.addEventListener('keydown', (e: KeyboardEvent) => {
    if (e.key === 'PrintScreen' || e.key === 'F13') {
        alert('test');
        document.body.style.zIndex = '999999';
        document.body.style.backgroundColor = 'black';
    }
})

return () => document.removeEventListener(‘keydown’)

}, [])

It should be something along these terms, didnt test it though.

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