为什么chrome在使用javascript打印时不显示图像并加载css

Why is chrome not showing the images and loading the css when print using javascript?

本文关键字:显示图 显示 图像 css 加载 chrome 打印 javascript 为什么      更新时间:2023-09-26

这是我的javascript,用于打印特定的div。它在IE和Mozilla中运行良好。但我只能看到没有任何风格和图像的文本。为什么?

var originalContents;
        function printDiv() {
            if (/MSIE ('d+'.'d+);/.test(navigator.userAgent)) {
                var DocumentContainer = document.getElementById('subcontent');
                var WindowObject = window.open('../print.aspx', 'popUpWindow', 'height=750,width=650,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
                WindowObject.document.write('<html><body><link href="/Scripts/style_print.css" rel="stylesheet" type="text/css"/><table><tr><td><div id="logo"></div></td></tr><tr><td align="left"><div id="siteloader"></div></td></tr></table>' + DocumentContainer.innerHTML + '</body></html>');
                WindowObject.document.close(); 
                WindowObject.print();
                WindowObject.close();
            }
            else {
                originalContents = document.body.innerHTML;
                var printable = document.getElementById('subcontent');
                document.body.innerHTML = printable.innerHTML;
                printCoupon();
            }
        }
        function printCoupon() {
            window.print();
            endPrintCoupon();
        }
        function endPrintCoupon() {
            document.body.innerHTML = originalContents; 
        }

WindowObject.close();对这行进行注释,然后用chrome重新检查。我也有同样的问题,现在通过评论这句话来解决。