实现方式:
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
问题一:这个效果实现的原理是什么,窗口为什么会自动关闭呢?
问题二:如果想要在用户点击了下载框中的"取消下载"或者"下载文件"按钮之后再关闭新窗口,要如何实现呢?
慕田峪7331174
相关分类