I have been attempting to print a dynamically created iFrame, then print it:
// CREATE iFrame
let iframe = document.createElement("iframe");
iframe.setAttribute('id', 'printerIFrame');
iframe.setAttribute('name', 'printerIFrame');
iframe.setAttribute('style', ' z-index: 1000;');
iframe.setAttribute('media', 'print');
let pageContent = document.createTextNode(createPrintableText(criteria));
// ADD iFrame to document
document.body.appendChild(iframe);
// POPULATE iFrame with print material
iframe = document.getElementById("printerIFrame");
body = iframe.contentWindow.document.getElementsByTagName('body')[0];
body.appendChild(pageContent)
// GET iFrame `window`
var x = document.getElementById("printerIFrame").contentWindow;
// IF NOT IE or Edge
x.document.close();
x.focus();
x.print();
iframe.parentNode.removeChild(iframe);
And this works... sort of. The problem is, when the print preview arrives, contained in the text are all the <[HTML]> tags that are on the iframe. And they're ignored. Instead of getting this:
Start Date: 01/01/2019
End Date: 01/31/2019
I'm getting something like this: Start Date: 01/01/2019<[br tag]>End Date: 01/31/2019<[br tag]>
Any ideas how to get this to work?