<form method="get" action="/app/PoiTemplate/NFC.xlsx">
<button type="submit">Download!</button>
</form>
window.open("/app/PoiTemplate/NFC.xlsx")
上面兩種方式都把文件給打開了, 還有其他下載方法嗎 ?
<a href="nfc.xlsx" download="nfc.xlsx">下載</a>
下面是php 的header,自己試試
header("Content-Type:?application/vnd.ms-excel;?charset=UTF-8"?);???
header("Pragma:?public"?);???
header("Expires:?0"?);???
header("Cache-Control:?must-revalidate,?post-check=0,?pre-check=0"?);???
header("Content-Type:?application/force-download");???
header("Content-Type:?application/octet-stream"?);???
header("Content-Type:?application/download"?);???
header("Content-Disposition:?attachment;filename=11.xls?"?);???
header("Content-Transfer-Encoding:?binary?"?);?
雖然IE不識別download屬性,但是IE下它任然是個鏈接,所以我們可以加一個 target="black"
屬性,來打開新窗口,實現(xiàn)下載,所以可以實現(xiàn)如下:
<a href="nfc.xlsx" download="nfc.xlsx" target="_blank">下載</a>
你的問題并不在前端,換一種思路,通過后端下載,隨便在前端發(fā)起一個get請求,在后端設置返回頭 Content-Disposition: Attachment; filename="文件名",并以流的形式,瀏覽器自然后彈出文件選擇框。這兒有個java例子https://github.com/treeandgra...
第二種思路:
/q/10...
javascrit的特點在于DOM和BOM的操作和引用,文件下載屬于Meta的特性,javascript無權操作,讓后端開發(fā)人員設置輸出的Head Meta即可。