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

I have a need where I have to print contents of a div. I am using above code to do so. It is working fine in IE but does nothing in Firefox. Am I missing something here that needs to be done in Firefox?

  • workaround for FF5 and chrome setInterval(), setTimeout() in inactive tab
  • Triggering a click() event in a timeout function
  • DOMCharacterDataModified not firing consistently across Firefox and Chrome. Who is correct?
  • Chrome does not resize SVG image
  • File access impossible in Firefox 17.0.1 extension
  • event.offsetX in Firefox
  • Does a Firefox Workers limit exist?
  • Why doesn't the JavaScript work for Firefox/Chrome but for IE?
  • How to access JavaScript execution trace at runtime in Firefox?
  • How can I provide a link inside my greasemonkey script to backup the GM_---value database?
  • Hide element with Javascript. Doesn't work with IE and Chrome
  • JSON.parse() problem with regular expression values
  • 6 Solutions collect form web for “window.print not working in Firefox”

    Uhm… your code seems to work fine for me, on Firefox 3.5 (Windows).
    It’s possible that are something wrong on your pnlDelete.ClientID?
    Your javascript code is rendered well on the page?

    Anyway I suggest you to use jQuery + a print plugin like this.

    Instead of opening a new window without any URL, I opened this page in the window and accessed the contents of the pnlSummary from the opened window via 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 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 on body onload.

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

    This is working fine in both IE and Firefox.

    Use setTimeout() function for loading the page. The example is given bellow link.

    http://oraclehappy2help.blogspot.in/2012/09/child-window-printing-problem-solution.html

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

    which is Fire fox Depended addon most usefulladdon In web-app Kisok in Firefox to select printer

    attached some example for attached printer and local printer it may help you to build without print dialog.

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

    Check to ensure your panel has something. My guess is prtContent is undefined

    Try this:

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

    you could try a jquery plugin…

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