簡體   English   中英

下載完成后如何關閉彈出窗口以下載文件

[英]How to close a popup downloading a file after the download is complete

我將查詢字符串發送到彈出窗口並從服務器下載文件。 下載完成后,我想關閉彈出窗口,但我不知道如何。

我發送查詢字符串的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中起作用並關閉窗口。

您可以在下載頁面的正文onload部分中使用自動關閉Javascript方法:

用在頭上

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

然后從body標簽調用函數:

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

這對我有用...

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM