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

373
Views
Open browser print window without using a package ReactJS

I want to print my whole page on react js without using a package. Is there any way to do this, i found Window.print() which does not seem to work.

Just want to open the browser print window. The shortcut for that is Ctrl+P on chrome so there could be a possibe way to press ctrl+p onClick of a button maybe.

<div>
<h1> Hello World </h1>
<button onClick = {DoPrint}></button>
</div>

Edit : Code to do this would be

Should work on all browsers except for Firefox For Android

<button className="DoTest" onClick={window.print}></button>

Thanks

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

0

You could declare your page with an iframe:

<iframe id="idofyourpage" style="position: absolute; ..."></iframe>

And then print it with something like this:

var myPrint = document.getElementById("idofyourpage").contentWindow;
myPrint.focus();
myPrint.print();

Also remember that you might need to open the document and write some content to it depending of your functionality. However, I remember having used window.print() successfully, so you would also like to make sure you used it correctly, since it's an easier and cleaner way to get your page printed in a component.

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!