Window.print()在Iphone Safari上不起作用

时间:2019-01-30 08:34:03

标签: javascript ios safari mobile-safari

在safari上打印时,popup加载为空,它适用于safari iphone以外的所有浏览器。我尝试在ajax调用之前加载弹出窗口,但根据我的应用程序用户,新打开的标签页会阻止所有javascript处理(当前运行页面除外),这意味着成功承诺不会得到解决

$scope.PrintDocument = function () {
                        var popupWin = window.open('', '_blank', 'width=600,height=600');
                        MyApi.PrintDocument()
                            .success(function (response) {

                                popupWin.document.open();
                                popupWin.document.write(response);
                                popupWin.document.close();
                                var is_chrome = Boolean(popupWin.chrome);
                                if (is_chrome) {
                                    popupWin.onload = function () { // wait until all resources loaded 
                                        popupWin.focus(); // necessary for IE >= 10
                                        popupWin.print();  // change window to mywindow
                                        popupWin.close();// change window to mywindow
                                    };
                                }
                                else {
                                    popupWin.document.close(); // necessary for IE >= 10
                                    popupWin.focus(); // necessary for IE >= 10
                                    popupWin.print();
                                    popupWin.close();
                                }
                            });
    }

0 个答案:

没有答案