window.close(); after window.print(); javascript

前端 未结 5 1728
北恋
北恋 2021-01-16 04:43

I need a js code which will close window right after appearing of pop up print window. Here is my code:

P         


        
5条回答
  •  佛祖请我去吃肉
    2021-01-16 04:51

    In this way, the window will close after print, works perfect!

    function printme() {         
         var newWindow = window.open();
         newWindow.document.open("text/html");
         newWindow.document.write('blablabla.......');
         newWindow.document.close();
    
         newWindow.print();
         newWindow.onfocus = function () {
            newWindow.close(); // Close the window
         }
    };
    

提交回复
热议问题