0
我有一个跟踪服务器上发生的事件数量的程序。我希望能够将单个事件详细信息导出到csv文件并允许用户下载它。link.click();在Chrome浏览器工作时无法在Internet Explorer中工作
我有一个按钮,上,看起来像这样的头版:
<button class="btn btn-main btn-actions-ok" ng-click="exportIncident()">Export Incident</button>
和在后端代码我有阵列称为阵列totaDatarow [];
$scope.exportIncident = function() {
var totalDataRow = [];
var csvContent = "data:text/csv;charset=utf-8,";
var exportDataHeader = ["Event Type", "User ID", "Event Date", "Description", "DocNum", "Library", "Version", "Comments"]
totalDataRow.push(exportDataHeader);
var incident = $scope.incident;
incident.details.forEach(function (detail) {
var exportDatarow = [];
//logic to add incident information to exportDatarow
totalDataRow.push(exportDatarow);
})
totalDataRow.forEach(function (infoArray) {
dataString = infoArray.join(",");
csvContent = csvContent + "\n" + dataString
});
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "Incident_"+ incident.id +".csv");
link.click();
}
,因为通过使用这种方式,我不能找到一种方法来定制,我生成的文件的文件名,我没有用window.open。所以我在按钮里面创建了一个链接并点击它下载。 在铬这个代码工作得很好。 csv文件被创建并下载。但是,在Internet Explorer中,此代码根本无法工作。 当我点击按钮时没有任何反应。 我通过调试器运行它,发现当Internet Explorer到达link.click()时。当它试图处理该行时,什么都不会发生。
我需要帮助,因为我不知道它是我的代码问题还是Internet Explorer兼容性问题?或别的什么谢谢。