實現(xiàn)方式:download.php $outputFileName = "test.xls"; header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header('Content-Disposition:inline;filename="' . $outputFileName . '"'); header("Content-Transfer-Encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache");index.html<html><head>
<script type="text/javascript">
window.open('download.php'); </script></head><body>
test</body></html>test.xls問題一:這個效果實現(xiàn)的原理是什么,窗口為什么會自動關(guān)閉呢?問題二:如果想要在用戶點擊了下載框中的"取消下載"或者"下載文件"按鈕之后再關(guān)閉新窗口,要如何實現(xiàn)呢?
效果: 文件下載框出現(xiàn)前彈出一個新窗口,下載框出現(xiàn)后新窗口自動關(guān)閉,問題如下:
繁星淼淼
2023-04-25 14:10:08