如何在下载完成后关闭下载文件的弹出窗口

时间:2014-12-28 12:30:35

标签: javascript c# asp.net

我向弹出窗口发送查询字符串并从服务器下载文件。 我想在下载完成后关闭弹出窗口,但我不知道如何。

我发送查询字符串的Javascript代码是:

var url = "../Msg/pgmsgAttachmentDownload.aspx?ID=" + ID;
window.open(url, '_blank', "top=100,left=100,menubar=0,resizable=1,width=670,height=520,scrollbars=yes,status=yes", true);

从弹出页面(pgmsgAttachmentDownload.aspx)下载文件的代码是:

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + newfilename + ";");
response.TransmitFile(Server.MapPath(bomsgAttachments.FilePath));
response.Flush();
response.End();

我的代码在Chrome中不起作用,但在IE和Firefox中工作并关闭窗口。

1 个答案:

答案 0 :(得分:0)

您可以在下载页面的正文onload部分使用自我关闭Javascript方法:

在脑袋中使用它



function windowclose() {
		window.open('', '_self', ''); 
		window.close();
    }




然后从body标签调用该函数:



<body onload="setTimeout('windowclose()',3000);">
&#13;
&#13;
&#13;

这适合我...

干杯

相关问题