2017-01-23 57 views
1

下面给出的事件被调用来将表中的数据导出到EXCEL中,代码的工作原理类似于Chrome中的魅力。在IE和Firefox我没有得到任何东西(文件,错误等)。 请帮助我前进和导出文件中的所有浏览器Excel导出无法在Firefox上正常工作,但在Google Chrome中正常工作

$("[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(); 
}); 
+0

请注明具体“不工作”。 – gus27

+0

我无法将指定内容导出到Excel中 – chandrahasan

+0

您应该尝试更具体。有没有错误信息?没有检索到文件?该文件格式错误? Excel打开文件时是否显示错误信息?等 – gus27

回答

3

使用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(); 
}); 

data:来自IE8的URI支持。但它“不能用于导航[...]”,所以我认为它不会在<a href="...">中工作。请参阅this link

+0

谢谢,它的工作完美@ gus27 – chandrahasan

+0

IE版本中仍存在问题:10.0.9200.17414 – chandrahasan

+0

@chandrahasan IE 10是否支持data:URI? – gus27

相关问题