2013-08-26 182 views
1

我有一个动态的div类。 div内的元素通过后端ajax Web服务请求动态填充。 : -打印div元素不适用于IE?

<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类里面有一个动态填充的元素列表。 我想在这个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; 
     } 

* 这个伟大工程,除了IE所有Web浏览器。 *

+1

先给窗口的名称看起来像一个有效的JavaScript标识符(不像“#hidden”)。 – Pointy

+0

你怎么用'#hidden'获得class =“hidden”'? – reyaner

+1

IE中有什么问题?你可以用你的代码创建一个jsfiddle吗? –

回答

4

这里是我使用的打印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(); 
    } 

请试试这个代码