JavaScript将JSP div数据导出到excel文件

JavaScript将JSP div数据导出到excel文件,javascript,jquery,Javascript,Jquery,我有一个用于将div数据导出到excel文件的java脚本代码: $(".excelIcon").click(function(e) { //getting values of current time for generating the file name var timeStamp = new Date().getTime(); //creating a temporary HTML link element (they support se

我有一个用于将div数据导出到excel文件的java脚本代码:

$(".excelIcon").click(function(e) {
        //getting values of current time for generating the file name
        var timeStamp = new Date().getTime();
        //creating a temporary HTML link element (they support setting file names)
        var a = document.createElement('a');
        var data_type = 'data:application/vnd.ms-excel';
        //getting data from our div that contains the HTML table
        var htmlImg = $('<div>').append($('.div1').clone()).html();
        var html = htmlImg.replace(/<img[^>]*>/g,"");
        var table_html = html.replace(/ /g, '%20');
        a.href = data_type + ', ' + table_html;
        //setting the file name
        a.download = 'file' + '_' + timeStamp + '.xls';
        //triggering the function
        a.click();
        //just in case, prevent default behaviour
        e.preventDefault();
    });
$(“.excelIcon”)。单击(函数(e){
//获取用于生成文件名的当前时间值
var timeStamp=new Date().getTime();
//创建临时HTML链接元素(它们支持设置文件名)
var a=document.createElement('a');
var data_type='data:application/vnd.ms excel';
//从包含HTML表的div中获取数据
var htmlImg=$('').append($('.div1').clone()).html();
var html=htmlImg.replace(/]*>/g,“”);
var table_html=html.replace(//g,'%20');
a、 href=数据类型+','+表格html;
//设置文件名
a、 下载='file'+'.'+timeStamp+'.xls';
//触发功能
a、 单击();
//以防万一,防止违约行为
e、 预防默认值();
});
我使用的类型为application/vnd.ms excel,这是microsoft将jsp数据导出到excel的标准,我的问题是该代码在chrome中运行,这意味着我可以在chrome中将jsp数据导出到excel,但在IE、safari和firefox中不起作用(我无法在这三个浏览器中从上述代码下载excel)。 谁能告诉我这些浏览器缺少什么。
提前感谢。

IE没有下载文件的可能原因是什么……我也尝试过从html中删除标签(IE可能不支持),但IE仍然没有下载excel文件。