I'm currently trying be able to print something to the screen using javascript. Right now, I've got a simple print function set up like below that gets triggered on a link press in HTML.
function print() {
console.log(printImgURL);
let w = window.open();
w.document.write(`<img src="${printImgURL}">`);
w.focus();
w.print();
w.close();
}
<a id="printButton" onclick="print()"title="Print"></a>
The content only appears when the link is pressed the second time (and any other time after), Although the console.log statement shows the proper URL to the image regardless if the image actually appears in the print dialogue or not. Does anyone have any idea why the content wouldn't be showing up the first the link is pressed?
Add href="#" in the anchor tag.
Example:
<a id="printButton" onclick="print()" title="Print" href="#"></a>