Printing contents of another page

后端 未结 6 1413
执笔经年
执笔经年 2021-01-02 04:15

In the following link

Print\"


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 05:03

    I know it´s an old question, but you can do it like this:

    function printExternal(url) {
        var printWindow = window.open( url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
        printWindow.addEventListener('load', function(){
            printWindow.print();
            printWindow.close();
        }, true);
    }
    

    Tested in Firefox and Chrome. IE9 doesn´t work.


    Edit 2020-04-03

    No longer work on Chrome, code adapted from Coder answer here:

    function printExternal(url) {
        var printWindow = window.open( url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
    
        printWindow.addEventListener('load', function() {
            if (Boolean(printWindow.chrome)) {
                printWindow.print();
                setTimeout(function(){
                    printWindow.close();
                }, 500);
            } else {
                printWindow.print();
                printWindow.close();
            }
        }, true);
    }
    

提交回复
热议问题