我有以下功能,在我测试过的几台 PC 上运行良好。我已经在 Chrome、IE 和 Firefox 上测试过,没有任何问题。但是,有一台特定的 PC(运行 Chrome)在该行抛出此错误“Uncaught TypeError: Cannot read property 'document' of undefined”:
win.document.write(data);
难道是因为win为null?
如果是这样,为什么这台特定 PC 会出现这种情况?
是否有一些 Chrome 设置需要设置?
方法:
function viewReport() {
console.info('generating event report');
var frmData = $('#frmEventReport').serializeArray();
var rptName = 'EventReport' + Math.floor((Math.random() * 100) + 1);
console.info('generated random report name ' + rptName);
$.ajax({
//type: "GET",
timeout: 120000,
url: '@Url.Action("EventReport", "Reports")',
data: frmData,
success: function (data) {
console.info('succesfully called back');
var win = window.open('', rptName, '_blank');
console.info('opening window');
win.document.write(data);
},
error: function (x, y, z) {
console.info(x + ' ' + y + ' ' + z);
}
});
}
最佳答案
该 PC 的 Chrome 是否启用了弹出窗口?如果不是,则无法创建新窗口,因此 win
是 undefined
关于javascript - 未捕获的类型错误 : Cannot read property 'document' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20797930/