为了账号安全,请及时绑定邮箱和手机立即绑定

效果: 文件下载框出现前弹出一个新窗口,下载框出现后新窗口自动关闭,问题如下:

效果: 文件下载框出现前弹出一个新窗口,下载框出现后新窗口自动关闭,问题如下:

繁星淼淼 2023-04-25 14:10:08
实现方式: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问题一:这个效果实现的原理是什么,窗口为什么会自动关闭呢?问题二:如果想要在用户点击了下载框中的"取消下载"或者"下载文件"按钮之后再关闭新窗口,要如何实现呢?
查看完整描述

1 回答

?
慕田峪7331174

TA贡献1828条经验 获得超13个赞

问题一 ... IE 就这样儿 ... 如果你用其他浏览器的话连新窗口都看不到 ...

问题二 ... 不直接弹 download.php ...

location.href 到 download.php 然后 window.close() ...


查看完整回答
反对 回复 2023-04-28
  • 1 回答
  • 0 关注
  • 105 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信