打印div元素不适用于IE? [英] Print div element doesn't work for IE?

查看:100
本文介绍了打印div元素不适用于IE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态div类。 div中的元素通过后端ajax Web服务请求动态填充。 : -

I have a dynamic div class. The elements inside the div are dynamically populated through backend ajax web service requests. :-

<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>

是动态填充的元素列表。
我正在尝试使用此div类中的打印按钮来打印所有元素。

inside this div class, a list of elements that are dynamically populated. I am trying to use a print button inside this div class to print all elements.

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;
        }

* 这适用于除IE以外的所有网络浏览器。 *

推荐答案

这是我用来打印DIV内容的代码,它的工作正常IE也是,

Here is the code which I'm using to print a DIV content, and its working fine in IE as well,

    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();
    }

请尝试此代码

这篇关于打印div元素不适用于IE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆