在我的代码中,我使用JavaScript在ASPX页面上触发一个window.open()
事件。我在这个页面的Page_Load()
事件中输出一个文件:
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();
之后我想关闭这个弹出窗口。但由于我已经改变了响应类型,所以无法在JavaScript中执行
window.close()
。它只会被附加到提供给用户的文件中。这个线程是我发现的最合适的解决问题的来源:Closing window after export to excel。但是给出的答案对我没有帮助,所以我基本上被卡住了。我不想告诉用户手动关闭窗口。你知道如何实现我的目标吗?