我在访问子窗口上的元素时遇到了一些麻烦。我收到的具体错误是:SCRIPT5007:无法获取未定义或空引用的属性'appendChild'。
首先,我打开一个新窗口并检索一个打印友好的发票模板,然后我继续生成一个表格,将其附加到新窗口中的发票中,但当我尝试“appendChild”时,我收到上述错误。
我能够使用相同的代码减去w成功地将表附加到父窗口,所以我认为我的表没有任何问题。我还尝试访问子窗口上的其他元素但没有成功。
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 }));
谢谢!
编辑:添加了更多代码。