[英]window.print not working in Firefox
function CallPrint() {
var prtContent = document.getElementById('<%= pnlDelete.ClientID %>');
var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write("<h3>Summary</h3><br />" + prtContent.innerHTML);
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close();
}
我需要打印div的內容。 我使用上面的代碼來做到這一點。 它在IE中工作正常但在Firefox中沒有任何作用。 我在這里錯過了一些需要在Firefox中完成的工作嗎?
使用setTimeout()
函數加載頁面。 下面給出了示例鏈接。
http://oraclehappy2help.blogspot.in/2012/09/child-window-printing-problem-solution.html
我沒有打開沒有任何URL的新窗口,而是在窗口中打開了這個頁面,並通過window.opener對象從打開的窗口訪問了pnlSummary的內容 -
function CallPrint() {
var winPrint = window.open('Print.aspx', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
}
在Print.aspx頁面上我使用了這個函數 -
function Print() {
var prtContent = "<h3>Summary</h3>" + window.opener.document.getElementById('ctl00_cphContent_pnlSummary').innerHTML;
document.getElementById("printDiv").innerHTML = prtContent;
window.print();
window.opener.focus();
window.close(); }
並在身體onload上調用它。
<body onload="Print();">
<form id="form1" runat="server">
<div id="printDiv">
</div>
</form>
</body>
這在IE和Firefox中都運行良好。
嗯......在Firefox 3.5(Windows)上,你的代碼似乎對我很好。 您的pnlDelete.ClientID可能有問題嗎? 您的javascript代碼在頁面上呈現得很好嗎?
無論如何,我建議你使用jQuery +的打印插件,像這樣 。
檢查以確保您的面板有一些東西。 我的猜測是prtContent
未定義
試試這個:
function CallPrint() {
var prtContent = document.getElementById('<%= pnlDelete.ClientID %>');
if (prtContent) {
var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write("<h3>Summary</h3><br />" + prtContent.innerHTML);
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close();
}
else {
alert('No summary available for printing');
}
}
你可以使用JS打印機設置https://addons.mozilla.org/en-us/firefox/addon/js-print-setup/ “
哪個是Fire fox Depended addon最有用的事情在Firefox中的web-app Kisok中選擇打印機
為附加的打印機和本地打印機附加了一些示例,它可以幫助您構建沒有打印對話框。
function EB_Print(printType) { try{ var printerType = printType; // type of the Print Code : network // Default Printer Configuring var Default_printer = "Canon MG2500 series"; /** local Printer configuring via Network ** Config teh Local server use \\\\\\\\ to get \\\\ **/ var Organizer_Printer = "\\\\\\\\network\\\\Canon LBP2900"; jsPrintSetup.setPrinter(Default_printer); jsPrintSetup.setSilentPrint(true);// withoud dialog /** alert(jsPrintSetup.getPrintersList()); // Debugger for the attached Printers list alert(jsPrintSetup.getPrinter()); // get the set printer Option **/ // id network is selected It will print the page in network if(printerType == 'network'){ jsPrintSetup.setPrinter(Organizer_Printer); } jsPrintSetup.print(); // Print the page }catch (e) { // TODO: handle exception } }
你可以嘗試一個jquery插件......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.