js window.open then print()

后端 未结 7 1911
深忆病人
深忆病人 2020-11-29 08:14

print() doesn\'t work in IE after opening a new window. It works in Chrome. Here\'s a tester:





        
7条回答
  •  死守一世寂寞
    2020-11-29 08:32

    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);
    

提交回复
热议问题