我一直拉我的頭髮了幾個小時試圖弄清楚。 我有一個我想要下載文件的iframe。這一切工作正常,但如果我的Response.ContentType = "APPLICATION/OCTET-STREAM";
Iframe onload下載文件時
我的JavaScript函數如下的iframe的onload不叫:
function DownloadStuff(){
var DownloadSource = "http://Apage.aspx"
var iframe = $("#hiddenDownloader");
if (iframe.attr("id") === undefined) {
$('<iframe />', { id: 'hiddenDownloader', onload:'javascript:alertReady();' }).appendTo('body');
iframe = $("#hiddenDownloader");
}
iframe.attr('src', DownloadSource);
}
function alertReady() {
alert("Ready");
}
我的服務器端代碼如下:
Response.Clear();
Response.CacheControl = "no-cache";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(false);
Response.ExpiresAbsolute = DateTime.Parse("1/1/2000");
Response.Expires = 0;
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("Content-Disposition", "attachment;filename=\"ReportDeck.pptx\"");
byte[] bytes = (byte[])PowerPointFile.Tables[0].Rows[0]["PPTBlob"];
bytes = Compression.DeCompressByteArray(bytes);
Response.OutputStream.Write(bytes, 0, bytes.Length);
如果我刪除調用onload的ContentType和Header,但不通過保存文件對話框下載該文件,而是將其寫入iframe。
任何幫助表示讚賞。
Regards, Byron Cobb。
謝謝。我有我的onload,因爲我在嘗試所有可能的解決方案之前,我意識到這是因爲內容類型。 – Bob 2010-09-29 10:47:56
mmm我問過類似的問題http://stackoverflow.com/questions/17184970/iframe-onload-wont-fire-when-dumping-a-file – 2013-06-19 08:23:31