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