Закройте окно после печати страницы - PullRequest
0 голосов
/ 18 июня 2020

Итак, я пытаюсь настроить новое окно, которое загружает некоторый контент (это потому, что контент был внутри iframe, а chrome не отображал никакого контента из этого iframe при попытке печати). Это новое окно позволяет пользователю печатать, а затем закрывается. Однако в более медленных браузерах функция закрытия срабатывает до загрузки окна печати, в результате чего окно закрывается. Есть ли у меня способ проверить поле печати перед закрытием, чтобы предотвратить это?

                // Check if the browser is chrome. If it is, load the iframe into a new window to print
                // as chrome doesnt allow for iframes to be printed within a page. if not, just print the page.

                var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
                if (isChrome) {
                    // Define iframe containing heatmap and a new window to print it in
                    var iframe = document.getElementById("heatmap");
                    var printWindow = window.open("","printwindow");

                    // Create css link for print window
                    var css = document.styleSheets[2].href;
                    var link = document.createElement("link");
                    link.type = "text/css";
                    link.rel = "stylesheet";
                    link.href = css;

                    // Create print window
                    printWindow.document.write("<html><head><title>Heatmap</title></head><body></body></html>");
                    printWindow.document.head.appendChild(link);
                    printWindow.document.body.appendChild(iframe);

                    // Print window and close after 3s to allow browser time to load iframe contents.
                    // Then reload the page to remove issues from duplicated ids.
                    setTimeout(function(){
                        printWindow.print();
                        printWindow.close();
                        window.location.reload(true);
                    }, 3000);
                } else {
                    window.print();
                    return false;
                }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...