I want to print a content of a html div and currently i am using this code.
<div id="content">
</div>
var printContents = document.getElementById("content").innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
printing is working correctly. But after that my other functions are stop responding. I'm using angular.js.
any idea?
Here is the answer I found
HTML and JS CODE
<div id="printable">
Print this div
</div>
<button ng-click="printDiv('printableArea');">Print Div</button>
$scope.printDiv = function(divName) {
var printContents = document.getElementById(divName).innerHTML;
var popupWin = window.open('', '_blank', 'width=300,height=300');
popupWin.document.open();
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + printContents + '</body></html>');
popupWin.document.close();
}
I found it from here
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