I am trying to print an image from inside a div, the code runs ok but when the print dialog pops up, I would like the page to stay the same while actually it is showing only the picture as the window.reload
doesn't work for some reasons. The javascript is telling me in console "Uncaught TypeError: window.reload is not a function"
but i don't understand why.
function printDiv(printableArea) {
var printContents = document.getElementById("printableArea").innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
window.close();
window.reload();
}
Click to print
<input type="button" onclick="printDiv('printableArea')" value="print a div!" />
You can use the following code: window. stop();
Window location.reload() The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.
The location.reload() method reloads the current URL, like the Refresh button.
location. reload() reloads the current page with POST data, while window. location. href='your url' does not include the POST data.
The reason you are getting the error is that there is no window.reload()
method. You might want to use location.reload()
to reload the page instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With