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

前端 未结 5 1665
北恋
北恋 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 05:02

    This code worked for me:

    print = function() {
        var printContents = document.getElementById('div').innerHTML,
          params = [
            'height=' + screen.height,
            'width=' + screen.width,
            'fullscreen=yes'].join(','),
    
        popup = window.open("", 'popUpWindow', params);
        popup.document.write(''
          + printContents
          + '');
        popup.onfocus = function () {
          setTimeout(function () {
            popup.focus();
            popup.document.close();
          }, 200);
        };
    };
    

提交回复
热议问题