开发者社区> 问答> 正文

文件下载框出现前弹出一个新窗口下载框出现后新窗口自动关闭的问题

实现方式:
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
效果:
文件下载框出现前弹出一个新窗口,下载框出现后新窗口自动关闭

问题一:这个效果实现的原理是什么,窗口为什么会自动关闭呢?

问题二:如果想要在用户点击了下载框中的"取消下载"或者"下载文件"按钮之后再关闭新窗口,要如何实现呢?

展开
收起
落地花开啦 2016-06-13 15:42:51 2861 0
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    问题一:使用的IE浏览器的原因
    问题二:不直接弹 download.php ,
    location.href 到download.php然后 window.close()

    2019-07-17 19:36:12
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载