I need to generate an HTML page, with an embedded logo and print it using just JavaScript, no jQuery.
This code works, some of the time. Most times, the image isn't printed, although if you close the print dialog box, the image is then in the generated document.
EDIT
Screen shots - common logo not displayed
Logo displayed
I think what is happening is that the browser hasnt had time to decode the base 64 img before its sent to print.
var player = GetPlayer();
var textEntry1=player.GetVar("Page1");
var textEntry2=player.GetVar("Q2");
var textEntry3=player.GetVar("Page2");
var contents = "<html><head></head><body style='width:650px;padding:20px;'>";
// Logo as base 64 encoded. Its about a 5Kb file. Chopped for clarity
contents+="<img src='data:image/png;base64,iVBOR ... gAAAABJRU5ErkJggg=='>";
contents+="<div style='font-size:26px;font-weight:bold;margin-top:26px;margin-bottom:20px;'>Print Your Answers to PDF or Paper</div>";
contents+="<div style='display:block;border-width:1px';><hr/></div>";
contents+="<div style='font-size:16px;font-weight:bold;'>Question 1</div>";
contents+="<p>"+textEntry1+"</p>";
contents+="<div style='font-size:16px;font-weight:bold;'>"+textEntry2+"</div>";
contents+="<p>"+textEntry3+"</p>";
contents+= "</body></html>";
var myWindow = window.open("","Print","width=810,height=610,scrollbars=1,resizable=1");
myWindow.document.write(contents);
myWindow.print();
I have tried
window.setTimeout(myWindow.print(), 3000);
and
myWindow.setTimeout(myWindow.print(), 3000);
Neither seem to work as the print dialog just appears without the wait.
Also tried myWindow.onload() but that doesn't even open the print dialog. Thanks