Print function in Chrome no longer working

前端 未结 6 1449
感情败类
感情败类 2020-12-03 19:36

Our website has a feature whereby a member profile can be printed. The way that it works is that a javascript function is attached to a button via an onsubmit. The javascrip

6条回答
  •  长情又很酷
    2020-12-03 19:52

    The Chrome is so fast that it actually call the print before the document is loaded. That's why the best thing to do is just moving the print function to onload, either like Mari or like this:

    winPrint = window.open("", "winPrint", "width=1,height=1");
    winPrint.document.write(html);
    winPrint.onload = function () {
        window.print();
        window.close();
    };
    

    And o.c. it's not working in IE so full code should look like this

    var is_chrome = Boolean(window.chrome);
    if (is_chrome) {
        winPrint.onload = function () {
            window.print();
            window.close();
        };
    }
    else {
        winPrint.print();
        winPrint.close();
    }
    

提交回复
热议问题