2013-08-26 184 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(); 
    } 

請試試這個代碼