this is my code
const printDiv = () => {
const printContents = document.getElementById('id').innerHTML;
const originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
return false;
};
i know when i using innerHTML gives me a string representation of the HTML within an element so i can't handle button or something like that.
actually, i can handle it with reload, but what is the best way? is there any option without reload which make me back to the same page?
const printContents = document.getElementById('id')
const win = window.open();
win.document.title ="some title";
win.document.body.innerHTML = printContents.innerHTML;
/* if content contains images that needs loading*/
const images = win.document.getElementsByTagName('img');
/*wait for them to load*/
win.print();