window.open打开文件乱码

问题:刚开始使用window.open在IE兼容模式下打开文件下载出现乱码。

 

一开始以为是文件名是中文导致的。然后使用a标签的download属性更改文件名解决。

<a class="hide" id="lindUlr"></a>$("#lindUlr").attr("href", path);

$("#lindUlr").attr("download", "123.xls");
document.getElementById("lindUlr").click();(使用$("lindUlr").click()是不起作用的

 

解决方案:

在web.xml里面加上下面两句:
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>

<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>

 
<mime-mapping >
<extension>xlsx</extension>  
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping> 

 

posted @ 2018-03-24 13:55  阿水写程序  阅读(4825)  评论(1编辑  收藏  举报