Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!