google chrome print preview does not load the page the first time

前端 未结 4 1271
刺人心
刺人心 2021-01-12 17:51

I\'m trying to print a page using this code



    

        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 18:09

    This worked for me (as well as implementing Anand's observed IE 10+ requirements):

    function Popup() {
        var _window = window.open('');
        _window.document.write(data);
    
        // required for IE >= 10
        _window.document.close();
        _window.focus();
    
        _window.document.body.onload = function() {
            // continue to print
            _window.print();
            _window.close();
        };
    
        return true;
    }
    

    Instead of waiting for the window to load and attempting to print it prematurely, this just waits for the entire document.body to load.

提交回复
热议问题