Window.print does not work 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();
    }

I have a need when I have to print the contents of a div. For this, I use the code above. It works fine in IE, but does nothing in Firefox. I missed something here, what needs to be done in Firefox?

+3
source share
6 answers

Instead of opening a new window without any URL, I opened this page in a window and accessed the contents of pnlSummary from an open window through the window.opener object -

function CallPrint() {
    var winPrint = window.open('Print.aspx', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
}

On the Print.aspx page, I used this function -

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

and called it when loading the body.

<body onload="Print();">
    <form id="form1" runat="server">
    <div id="printDiv">
    </div>
    </form>
</body>

This works great in both IE and Firefox.

+2
source

... , , , Firefox 3.5 (Windows). , - pnlDelete.ClientID? javascript- ?

jQuery + , this.

+1

, -. prtContent undefined

:

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');
    }
}
+1

JS Printer Setup https://addons.mozilla.org/en-us/firefox/addon/js-print-setup/"

Fire fox. . - Kisok Firefox .

attached example for a connected printer and local printer, this can help you build without a print dialog. A.

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
	}
	
}
Run codeHide result
+1
source

you can try jquery plugin ...

http://plugins.jquery.com/project/PrintArea

0
source

Source: https://habr.com/ru/post/1727220/


All Articles