ordersprinter/webapp/elements/localprint.js

32 lines
834 B
JavaScript
Raw Normal View History

2020-11-19 22:47:44 +01:00
/**
*
*/
function closePrint () {
document.body.removeChild(this.__container__);
}
function setAndStartPrint () {
this.contentWindow.__container__ = this;
this.contentWindow.onbeforeunload = closePrint;
this.contentWindow.onafterprint = closePrint;
this.contentWindow.focus(); // Required for IE
this.contentWindow.print();
}
function printContent (content) {
var printiframe = document.createElement("iframe");
printiframe.setAttribute("id", "printiframe");
printiframe.onload = setAndStartPrint;
printiframe.style.visibility = "hidden";
printiframe.style.position = "fixed";
printiframe.style.right = "0";
printiframe.style.bottom = "0";
var htmlBody = '<body>' + content + '</body>';
printiframe.src = 'data:text/html;charset=utf-8,' + encodeURI(htmlBody);
document.body.appendChild(printiframe);
}