Print Popup In Javascript Missing Images
I want to open a new window/tab, put some HTML in the document, then bring up the browser print dialog to print that new window. I am using the following to accomplish this: var w
Solution 1:
Try putting your printer call in an onload event for the last image.
<imgonload="window.print()"... />
EDIT:
Full answer by OP as seen below:
I came up with the following script using @chockleyc's answer as inspiration. I couldn't just use the last image because they don't necessarily load in order. The following script will print the page after all images have loaded (uses jQuery):
var hasPrinted = false;
$(document).ready(function(){
$('img').load(function(){
var imgs = $('img');
var loadedAll=true;
for(var i=0;i<imgs.length;i++){
loadedAll &= $(imgs[i])[0].complete;
}
if (loadedAll && !hasPrinted) {
console.log('printing');
hasPrinted = true;
window.print();
}
else {
console.log('not all images have loaded');
}
})
});
Solution 2:
Try changing it from the body.onload
event to the window.onload
event.
w.window.onload = window.print()
Or something like that.
Post a Comment for "Print Popup In Javascript Missing Images"