I have this javascript code attached that puts some content into a popup window and then tries to print it:
$(".print_friendly_popup").click(function() {
var target = $(this).data('print-target');
var left = (screen.width/2)-(500/2);
var top = (screen.height/2)-(500/2);
var win = window.open("", "test", "width=500,height=500 top=" + top + ", left=" + left);
if(target == 'review') {
win.document.write($('#print_friendly_review').html());
} else if(target == 'essay') {
win.document.write($('#print_friendly_essay').html());
}
win.print();
win.close();
});
The problem is sometimes the call to win.document.write takes too long and the window tries to print a blank screen. How do I wait for window.document to be written to before firing print?