What worked for me was adding myWindow.document.close()
after myWindow.document.write()
. Here's my solution with a timeout to wait for the new window to finish loading (if you have a lot to load):
var win = window.open('', 'PrintWindow');
win.document.write('Stuff to print...');
setTimeout(function () {
win.document.close();
win.focus();
win.print();
win.close();
}, 1000);