0

这是我的 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; 
        }
4

1 回答 1

2

WindowObject.close(); 评论这一行并在 chrome 中重新检查。我有同样的问题,现在通过评论这一行来解决。

于 2013-10-21T05:45:55.063 回答