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> 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM