Link to home
Start Free TrialLog in
Avatar of Susan Faul
Susan Faul

asked on

Javascript print function no longer works

I have javascript code in an aspx page to print 4 copies of a document from one button click  (see code below).  When using Windows 7 and Internet Explorer, this worked fine.  Now with Windows 10, it no longer works.  It will print 1 copy only.  Anyone have any suggestions?  

<input type="button" id="btnPrint" name="button" value="Print Stuff" onclick="JavaScript:PrintPart('PrintThisPart');return false;");  />



 
  function PrintPart(elementID) {
        var printContent = document.getElementById(elementID);
        var printWindow = window.open('', '', 'left=50000,width=0,height=0');

        document.getElementById('ctl00_ContentPlaceHolder2_btnA').click();

        document.getElementById('dontprint').style.display = 'none';
        document.getElementById('dontprintHistory').style.display = 'none';

        document.getElementById('ctl00_ContentPlaceHolder2_txtNotes').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder2_lblNotes').style.display = 'none';

        document.getElementById('ctl00_ContentPlaceHolder2_lbl1').style.fontSize = "22px";

        document.getElementById('ctl00_ContentPlaceHolder2_lblCopyTo').innerHTML = '' +
                     Name: _______________________________________ <br />' +
                     Date:____________________________________ <br />' +
                     '<br /><br /> COPY ONE';

        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();

        document.getElementById('ctl00_ContentPlaceHolder2_lbl1').innerHTML = 'COPY TWO';
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();

        document.getElementById('ctl00_ContentPlaceHolder2_lbl1').innerHTML = 'COPY THREE';
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();

        document.getElementById('ctl00_ContentPlaceHolder2_lbl1').innerHTML = 'COPY FOUR';

        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();

        printWindow.close();

    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Q1. What version of Windows 10 and IE are you using?
There was error in Windows 10 that was later fixed. See more details here
Q2. Is your printer setup properly?
Do not use your script just try to print your page using Windows (e.g. using CTRL +P or by IE menu. This Print shall work  in order for your code to work
Avatar of Susan Faul
Susan Faul

ASKER

The suggestion to look for errors using the console was not something i thought of, but lead me to the piece of code that was causing the problem.

Thank you Julian Hansen.
You are welcome.
Initially, my javascript print function did a print.window 4 separate times.  I changed that function to call 4 other functions to do the print.  This now works with Windows 10, Microsoft Edge, with pop up blockers turned off.  But, i cannot get this work with Google Chrome or Internet Explorer 11.  I've tried setting it to allow pop ups from my website, and then i turned off pop blockers completely, but i can only get the first document to print.  Any ideas?  Is there an issue with pop up blockers on Chrome and IE?  Since i do have a solution, this is not as much of an issue, but i am curious if anyone knows why this won't work.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: 'Julian Hansen' (https:#a42983337)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer