0

I am having some trouble with accessing elements on a child window. The specific error I am receiving is: SCRIPT5007: Unable to get property 'appendChild' of undefined or null reference.

First I open a new window and retrieve a print-friendly invoice template then I proceed to generate a table to be appended to the invoice in the new window but when I attempt to "appendChild" I receive the error above.

I am able to successfully append the table to the parent window using the same code minus the w, so I don't think there is anything wrong with my table. I have also tried to access other elements on the child window with no success.

 var xhr = new XMLHttpRequest();
     xhr.open('POST', '/detailedinvoice');
     xhr.setRequestHeader('Content-Type', 'application/json');
     xhr.responseType = 'json';
     xhr.onload = function () {

          var invoicejson = (xhr.response)[0].invoice;
          var contractor = (xhr.response)[0].contractor;
          var invoicejson = JSON.parse(invoicejson);
          var w = window.open('http://localhost:3000/invoiceejs', 
          'Invoice');

          $(w.document).ready(function () {
               var tableinvoice = w.document.createElement("table");
               var header = tableinvoice.createTHead();
               tableinvoice.setAttribute("id", "tableinvoice");

               var row = header.insertRow(0);
               .......

          w.document.getElementById("invtbl").appendChild(tableinvoice);

     });
 };

 xhr.send(JSON.stringify({ Id: invoiceid }));

Thanks!

Edit: added more code.

jrl98
  • 23
  • 3

0 Answers0