3

我正在使用 kendo ui 控件,当从网格中导出表格数据在 chrome 中工作正常但在 IE 10 和 mozilla firefox 中不起作用。这是我的小提琴代码:http: //jsfiddle.net/SZBrt/41/enter code here

   var data = filteredDataSource.view();

    var result = "data:application/vnd.ms-excel,";

 result += "<table><tr><th>OrderID</th><th>Freight</th><th>Order Date</th><th>Ship Name</th><th>Ship City</th></tr>";

 for (var i = 0; i < data.length; i++) {
     result += "<tr>";

     result += "<td>";
     result += data[i].OrderID;
     result += "</td>";

     result += "<td>";
     result += data[i].Freight;
     result += "</td>";

     result += "<td>";
     result += kendo.format("{0:MM/dd/yyyy}", data[i].OrderDate);
     result += "</td>";

     result += "<td>";
     result += data[i].ShipName;
     result += "</td>";
     result += "<td>";
     result += data[i].ShipCity;
     result += "</td>";
     result += "</tr>";
 }
  result += "</table>";
4

1 回答 1

1

事实上,您的方法目前仅在 Chrome 中受支持。对于 Firefox,您需要 window.open 和 IE 10 - window.navigator.msSaveOrOpenBlob

if (window.navigator.msSaveBlob) {
        window.navigator.msSaveBlob(new Blob([result]), 'export.csv');
 } else {
   window.open(result);
 }

这是适用于 Firefox 和 IE 10 的更新小提琴:http: //jsfiddle.net/SZBrt/92/

这篇博文中有很多信息:http: //hackworthy.blogspot.com/2012/05/savedownload-data-generated-in.html

于 2013-09-02T12:58:08.777 回答