Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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();
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top