简体   繁体   English

打印div元素不适用于IE吗?

[英]Print div element doesn't work for IE?

I have a dynamic div class. 我有一个动态的div类。 The elements inside the div are dynamically populated through backend ajax web service requests. div中的元素是通过后端ajax Web服务请求动态填充的。 :- :-

<div class="hidden">

       <asp:Button ID="Button1" runat="server" 
        Height="23px" style="margin-top: 0px" Width="69px" text="Print" OnClientClick="PrintElem('#hidden'); return false;"/>
</div>

inside this div class, a list of elements that are dynamically populated. 在此div类中,列出了动态填充的元素。 I am trying to use a print button inside this div class to print all elements. 我正在尝试在此div类中使用打印按钮来打印所有元素。

function PrintElem(elem) {
            Popup($(elem).html());
        }

        function Popup(data) {
            var mywindow = window.open('', '.hidden', 'height=400,width=600');
            mywindow.document.write('<html><head><title>Pharmacy List</title>');
            /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
            mywindow.document.write('</head><body >');
            mywindow.document.write(data);
            mywindow.document.write('</body></html>');

            mywindow.print();
            mywindow.close();

           return true;
        }

* This works great for all web browsers except for IE. * 这对除IE之外的所有Web浏览器都适用。 * *

Here is the code which I'm using to print a DIV content, and its working fine in IE as well, 这是我用来打印DIV内容的代码,它在IE中也能正常工作,

    function printPartOfPage(elementId) {
        var printContent = document.getElementById(elementId);
        var windowUrl = 'Job Receipt';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();
        var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    }

Please try this code 请尝试此代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM