Reputation: 1133
Im aware that it is not possible to download multiple files using the same windows as HTTP does not allow it.
But I managed to do it using the code below:
$('#test').on("click",function(e){
window.location="getEmployeeInstructions.php";
setTimeout(function(){ window.location="getMergedEmployeeReports.php"; }, 10000);
setTimeout(function(){ window.location="getQualityHandbook.php"; }, 20000);
setTimeout(function(){ window.location="getEquipmentReport.php"; }, 30000);
return false;
});
Not a very clean or usefull way to do it, as it requires each download to be done before the next one can execute.
So i was thinking. Is there a way to be notified when a file has been downloaded and initiate the next file download instead of using the setTimeout function to postpone each download ? That way i can at least notify the user of the progress and make him aware that the page is working on his request..
Update: Being notified is not a requirement for me if im able to start multiple downloads at once and not forced to start the next download once the previous file was completed.
Upvotes: 2
Views: 1635
Reputation: 66
I Just solve similar task today. Use src attribute of hidden iframe. Its handle file downloading without parent page changing. And this way will not be blocked as multiply popups.
<iframe id="downloader1" style="display:none"></iframe>
<iframe id="downloader2" style="display:none"></iframe>
<iframe id="downloader3" style="display:none"></iframe>
$('#test').on("click",function(e){
$("#downloader1").attr("src", "file1.php");
$("#downloader2").attr("src", "getQualityHandbook.php");
$("#downloader3").attr("src", "getEquipmentReport.php");
return false;
});
One addition. When getQualityHandbook.php return error instead file, maybe you vant to handle this situation:
$('#downloader2').unbind().load( function()
{//handle if not file received
var data = $('#downloader2').contents().find('body ').html();
alert(data);
});
Upvotes: 1
Reputation: 3729
$('#test').on("click",function(e){
window.open("getEmployeeInstructions.php", 'download1');
window.open("getMergedEmployeeReports.php", 'download2');
window.open("getQualityHandbook.php", 'download3');
window.open("getEquipmentReport.php", 'download4');
return false;
});
Upvotes: 0