views:

50

answers:

2

I have a form in an iframe, when this form is posted a file is returned to the user (based on the form information). This file is returned using content-disposition:attachment so that only a file save dialog shows up. I want to do something in javascript once the file has been returned to the user. I tried attaching a $(iframe).ready(); to the iframe after the form is posted, but it goes off instantaneously.

Worth noting: $(iframe).load(); does not work either, it is never triggered. The form post is technically the second load of the iframe (the first load displays the form in the iframe).

Any ideas?

A: 

Only thing that comes to mind is to not immediately send the file back to the user, but to output a HTML skeleton that 1. Executes the Javascript and 2. when that is done, redirects to the download file (maybe with an additional <meta> redirect to make sure it works out). Other than that, I don't think you will have much chance of executing Javascript together with delivering a downlad file.

Pekka
This won't work as I need it to, the processing of the file can take 30+ seconds. When the download is triggered I set a processing function going, when the download is "ready" I want to end the processing function and provide the user with some additional information.
aepheus
Why not save the file in a temporary location (rather than outputting it directly) and redirect the user there after showing the info?
Pekka
This may work, it would at least allow me to end the processing function and display the addition information through an intermediary page. Though, I am concerned about scalability when saving all these files server-side.
aepheus
I see. Well the only other thing that comes to mind is splitting the process into iframes, and having a 2nd iframe that constantly polls whether the processing is finished. When it is, it will display the information, and the download dialog will pop up in the other iframe at the same time.
Pekka
A: 

You could try adding some script in the iframe callback after form submit that will run a function in the parent window?

Parent Window

function test(){
 alert('Success!');
}

Callback iFrame

$(window).load(function(){
 parent.test();
})
fudgey