文件写入响应后,关闭弹出窗口 [英] Closing a Pop-Up Window after Writing File to Response
问题描述
在我的code,我使用JavaScript来火了一个ASPX页面上的window.open。在该页面的页面加载,我输出文件:
In my code, I am using JavaScript to fire off a window.open on an ASPX page. In the page-load of that page, I'm outputting a file:
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\";");
outputStream.WriteTo(Response.OutputStream);
outputStream.Flush();
outputStream.Close();
Response.Flush();
Response.Close();
在此之后,我想最好想关闭弹出窗口。但是,因为我已经改变了我的反应类型,我不能输出正常window.close的JavaScript。它将仅仅获得附加到该文件被提供给用户。我是来解决最接近的是这个线程:
After this, I would ideally like to close the popup window. However, because I have changed my response type, I cannot output the normal window.close JavaScript. It will merely get appended to the file being given to the users. The closest I have come to a solution is this thread:
http://forums.asp.net/t/1186371.aspx?的PageIndex = 1
不过,即使到底有没有的家伙没有得到任何答案。据我所看到的,有没有办法做到这一点。不过,我想请你帮忙之前,我放弃了全部,只是有一些告诉用户手动关闭该窗口。有什么建议?
But even there in the end the guy didn't get any answers. As far as I can see, there is no way to do this. However, I'd like to ask you for your help before I give it up entirely and just have something telling the users to close the window manually. Any suggestions?
推荐答案
我会建议你通过一个简单的射击文件的下载
I would suggest you firing the download of the file via a simple
<a href="/path/to/your/page.aspx" target="_blank">Download</a>
这将调用不同的窗口您的网页,下载将开始和页面应该自动关闭。
This will call your page in a different window, the download will start and the page should automatically close.
这篇关于文件写入响应后,关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!