thenashone thenashone - 5 months ago 13
PHP Question

Posting data to a iframe then download a file from a link

I am having an issue with posting some data to an iframe then for it to download a file from a link.

I have searched stackoverflow for similar questions and have tried to adapt my code to make this work with the information i had found.

Currently it only posts the data to the iframe.

here is my code

<script src=""></script>
<form action="" method="post" target="output_frame" accept-charset='UTF-8'>
<input type='hidden' name='package_shape' value='box' />
<input type="submit" name='op' id='go' value='download' />
var downloadUrl = '';

$('#myFrame').on('load', function(){
console.log('WOOT!', arguments);

$('#go').on('click', function(){
$('#myFrame').attr('src', downloadUrl);
<iframe name="output_frame" src="" width="100%" height="500" id="myFrame">

If i created a button
<button id="go"/>Download</button>
and press it after the page has loaded within the iframe, it downloads the right file.

Thank you in advance.


If you want to send POST data to output URL, and also set downloadable URL:

$('#go').on('click', function(){
    $('#myFrame').on('load', function(){ $('#myFrame').attr('src', downloadUrl); } );
   //setTimeout( function(){ $('#myFrame').attr('src', downloadUrl); }, 500 );