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

ASP.NETWindows 10JavaScriptWindows OSWindows 7

Avatar of undefined
Last Comment
Seth Simmons

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Miguel Oz

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
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.
Julian Hansen

You are welcome.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Susan Faul

ASKER
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.
Seth Simmons

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