Excel导出不适用于Firefox,但在谷歌crome中正常工作 [英] Excel export not working on Firefox but working fine in google crome
问题描述
调用下面给出的事件将表格中的数据导出为EXCEL,代码就像Chrome中的魅力一样。在IE和Firefox中,我没有得到任何东西(文件,错误等)。
请帮助我继续并在所有浏览器中导出文件
The below given event is called to export the data in the table into an EXCEL , The code works like a charm in Chrome . In IE and Firefox i am not getting anything(File, error etc). Kindly assist me to go forward and export the file in all the browsers
$("[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,您必须明确添加链接
元素到DOM之后才能执行 .click()
:
With Firefox you have to explicitly add the link
element to the DOM before you can execute .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支持数据:
URI 。但它不能用于导航[...]所以我认为它不适用于< a href =...>
。请参阅此链接。
The data:
URI is supported from IE8. But it "cannot be used for navigation [...]" so I assume it will not work in an <a href="...">
. See this link.
这篇关于Excel导出不适用于Firefox,但在谷歌crome中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!