• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 13次浏览 已收录 0个评论
文章目录[隐藏]

实现方式:
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(<b>6本文来源gao@dai!ma.com搞$代^码!网7</b><pre>搞gaodaima代码

“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

	<script type="text/javascript">		window.open('download.php');	</script><body>	test

test.xls

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

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

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

回复内容:

实现方式:
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

	<script type="text/javascript">		window.open('download.php');	</script><body>	test

test.xls

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

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

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

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

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

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:javascript – 文件下载框出现前弹出一个新窗口下载框出现后新窗口自动关闭的问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址