Excel export 在 Firefox 上不工作,但在 google crome 上工作正常
Excel export not working on Firefox but working fine in google crome
调用下面给定的事件将 table 中的数据导出到 EXCEL 中,该代码在 Chrome 中就像一个魅力。在 IE 和 Firefox 中我没有得到任何东西(文件、错误等)。
请协助我继续并在所有浏览器中导出文件
$("[id$=myButtonControlID]").click(function(e) {
var result = 'data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=printHead]').html());
var link = document.createElement("a");
link.download = "Reports";
link.href = result;
link.click();
});
对于 Firefox,您必须明确地将 link
元素添加到 DOM 才能执行 .click()
:
$("[id$=myButtonControlID]").click(function(e) {
var result = 'data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=printHead]').html());
var link = document.createElement("a");
document.body.appendChild(link); // You need to add this line
link.download = "Reports";
link.href = result;
link.click();
});
IE8 支持 data:
URI。但它 "cannot be used for navigation [...]" 所以我认为它不会在 <a href="...">
中工作。参见 this link。
调用下面给定的事件将 table 中的数据导出到 EXCEL 中,该代码在 Chrome 中就像一个魅力。在 IE 和 Firefox 中我没有得到任何东西(文件、错误等)。 请协助我继续并在所有浏览器中导出文件
$("[id$=myButtonControlID]").click(function(e) {
var result = 'data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=printHead]').html());
var link = document.createElement("a");
link.download = "Reports";
link.href = result;
link.click();
});
对于 Firefox,您必须明确地将 link
元素添加到 DOM 才能执行 .click()
:
$("[id$=myButtonControlID]").click(function(e) {
var result = 'data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=printHead]').html());
var link = document.createElement("a");
document.body.appendChild(link); // You need to add this line
link.download = "Reports";
link.href = result;
link.click();
});
IE8 支持 data:
URI。但它 "cannot be used for navigation [...]" 所以我认为它不会在 <a href="...">
中工作。参见 this link。