简体   繁体   English

未捕获的类型错误:无法读取未定义的属性“文档”

[英]Uncaught TypeError: Cannot read property 'document' of undefined

I have the following function, which works fine on a few PCs that I've tested on.我有以下功能,它在我测试过的几台 PC 上运行良好。 I've tested this on Chrome, IE & Firefox with no issues.我已经在 Chrome、IE 和 Firefox 上测试过,没有任何问题。 However, there's 1 particular PC (running Chrome), that throws this error "Uncaught TypeError: Cannot read property 'document' of undefined" on the line:但是,有 1 台特定的 PC(运行 Chrome)会在行上引发此错误“Uncaught TypeError: Cannot read property 'document' of undefined”:

                win.document.write(data);

Could it be because win is null?可能是因为 win 为空?

If so, why is this the case on this particular PC?如果是这样,为什么在这台特定的 PC 上会出现这种情况?

Is there some Chrome settings that needs to be set?是否有一些 Chrome 设置需要设置?

Method:方法:

    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);
            }
        });
    }

Are popups enabled on that PC's Chrome?该 PC 的 Chrome 是否启用了弹出窗口? If they're not then the new window cannot be created hence win is undefined如果不是,则无法创建新窗口,因此win undefined

This is because when you try to create a pop-up after the success of asynchronous ajax request win get undefined .这是因为当您尝试创建一个弹出式异步Ajax请求成功后win得到undefined So you can add async:false as follows this is works for me:所以你可以添加async:false如下,这对我有用:

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,
        async:false,
        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);
        }
    });
}

出现此错误是因为系统中禁用了弹出窗口。因此,通过系统设置选项启用弹出窗口。

I have the following function, which works fine on a few PCs that I've tested on.我具有以下功能,该功能可以在经过测试的几台PC上正常运行。 I've tested this on Chrome, IE & Firefox with no issues.我已经在Chrome,IE和Firefox上进行了测试,没有任何问题。 However, there's 1 particular PC (running Chrome), that throws this error "Uncaught TypeError: Cannot read property 'document' of undefined" on the line:但是,有1台特定的PC(运行Chrome),在行上抛出此错误“ Uncaught TypeError:Can not read property'document'of undefined”的行:

                win.document.write(data);

Could it be because win is null?可能是因为胜利为空吗?

If so, why is this the case on this particular PC?如果是这样,为什么在此特定PC上会出现这种情况?

Is there some Chrome settings that needs to be set?是否需要设置一些Chrome设置?

Method:方法:

    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);
            }
        });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 D3.js:未捕获的TypeError:无法读取未定义的属性“文档” - D3.js : Uncaught TypeError: Cannot read property 'document' of undefined on $(document).foundation(); 未捕获的TypeError:无法读取未定义的属性“top” - on $(document).foundation(); Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined 未捕获的TypeError:无法读取未定义的属性“数量” - Uncaught TypeError: Cannot read property 'quantity' of undefined 未捕获的TypeError:无法读取未定义的属性'fromJSON' - Uncaught TypeError: Cannot read property 'fromJSON' of undefined 未捕获的TypeError:无法读取未定义的属性“ timing” - Uncaught TypeError: Cannot read property 'timing' of undefined 未捕获的TypeError:无法读取未定义的属性'formatter' - Uncaught TypeError: Cannot read property 'formatter' of undefined Uncaught TypeError:无法读取未定义的属性“ stopVideo” - Uncaught TypeError: Cannot read property 'stopVideo' of undefined 未捕获的类型错误:无法读取未定义的属性“setCrossOrigin” - Uncaught TypeError: Cannot read property 'setCrossOrigin' of undefined 未捕获的TypeError:无法读取未定义的属性'NaN' - Uncaught TypeError: Cannot read property 'NaN' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM