首页 > 解决方案 > JavaScript 在带有 Error-DOM7011 的 IE 11 中不起作用

问题描述

此代码是上传一个csv文件并更改为表格形式。它适用于 chrome 和 safari,但不适用于 IE……我不知道我应该改变什么。我想知道如何解决它。

DOM7011:此页面上的代码禁用了前后缓存。有关详细信息,请参阅:http: //go.microsoft.com/fwlink/ ?LinkID=291337 。

var numQ = 0;

function openCsvFile(){
    var input = document.createElement("input");

    input.type = "file";
    input.accept="text/plain, text/html, .jsp, .csv";

    input.click();
    input.onchange = function(event){
        processFile_csv(event.target.files[0]);

    };  
}

function processFile_csv(file){
    var pass_head = 0;
    var reader = new FileReader();
    reader.readAsText(file, "UTF-8");
    reader.onload = function(){
        var allRows = reader.result.split(/\r?\n|\r/);
        var table = '<!DOCTYPE html><html lang="ko"><head><meta charset="UTF-8"><meta http-equiv pragma content no-cache ><meta http-equiv="X-UA-Compatible" content="IE=Edge; chrome=1" /><meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Expires" content="0"></head><table id="output" border="1">'; 

        for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
            if (singleRow === 0) {
                table += '<thead>';
                table += '<tr align ="center">';

            } else {
                table += '<tr align = "center">';
            }

            var rowCells = allRows[singleRow].split(',');
            for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
                if (singleRow === 0) {
                    table += '<th align = "center">';
                    table += rowCells[rowCell];
                    table += '</th>';

                } else {
                    if (rowCells[0] != "") {
                        table += '<td align = "center">';
                        if(rowCell == 0){
                            table += "a";
                        } 
                        table += rowCells[rowCell];
                        table += '</td>';
                    }
                }
            }

            if (singleRow === 0) {
                table += '</tr>';
                table += '</thead>';
                 table += '<tbody>';

            } else {
                table += '</tr>';
            }
        } 
        document.getElementById("output").innerHTML = table;
    };
}

标签: javascripthtml

解决方案


推荐阅读