I have a textarea that displays a report with keywords like "FAIL", "WARNING", "ERROR". I want to be able to print this textarea with the highlighted colors included.
Currently, I am able to print my textarea using the following function (without highlighted colors):
js:
function printTextArea() {
childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
childWindow.document.open();
childWindow.document.write('<html><head></head><body>');
childWindow.document.write(document.getElementById('textArea').value.replace(/\n/gi,'<br>'));
childWindow.document.write('</body></html>');
//this doesn't highlight the text in my print prompt window
childWindow.document.body.innerHTML.replace(/FAIL/g,"<span class='highlight'>FAIL</span>");
childWindow.print();
childWindow.document.close();
childWindow.close();
}
css:
body {
-webkit-print-color-adjust: exact !important;
}
.highlight {
background-color: yellow;
}
Also, when I view the html before the print()
I see the correct class appended to my keyword:
<span class='highlight'>FAIL</span>
I'm trying to add the highlight class when writing to the new window and print with highlighted text but it doesn't seem to work. Is there something I am doing wrong?