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

179
Views
window.print() not working inside useeffect (or anywhere on page)

I am trying to call window.print() and nothing happens. In the same place, I try window.alert('test') and it works.

any ideas?

a different page in my application does successfully call window.print() so I'm thinking it's not a printing setting on my machine

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

window.print was being blocked by an element on the page.

I got it to work using the react-to-print. If you look at the code behind react to print, you'll see it doesn't quite use window.print, rather some other thing like (target.contentWindow.print();). And in the readme of it, you can see it was explicitly created for scenarios where window.print was blocked - like firefox. enter image description here

Implementation of this is like this:

  1. add a useRef variable and set it to an element on the page (either a div perhaps or else a component.

const componentRef = useRef(); const handlePrint = useReactToPrint({ content: () => componentRef.current!})

<div css={{ display: 'none', '@media print': { display: 'block' } }} ref={componentRef}> <CoversheetPrint {...coversheetData} />         
</div>

https://github.com/gregnb/react-to-print/search?q=window.print

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!