How to capture the onload event of a window with attachment response?
I have the following download request in javascript:
var exportWindow = window.open('Download.ashx?source=1', '');
exportWindow.onload = function() {
alert('finished');
};
My problem is that the above alert box does not appear. The download.ashx sets up the following response (which will be saved as a csv file), which works fine.
context.Response.ClearContent();
context.Response.ContentType = "application/text";
context.Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
context.Response.Write(resultWriter开发者_如何转开发.ToString());
context.Response.Flush();
context.Response.Close();
If I replace the download.ashx with a normal aspx page, then the alert appears. So my question would be: is it possible to know programatically when the dowload.ashx returned with a response? (using FF3)
Thanks in advance, Geza
I don't believe that you can do this.
If you think about it from a content type perspective, you are loading a page that is of type application/text
, which has no DOM model or API defined, so you cannot expect DOM methods and events to be available. At least this is my understanding of the situation.
I've seen this type of question on SO before, but I've never seen a simple answers like the one that you are expecting.
use firebug - and trace what is going on with console.log - it seems like it's not getting to the alert at all. In ie you can use firebug lite. You might also need to use the name of the window to target it.
精彩评论