Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Javascript multiple file download queue

This piece of code allows you to force users to download multiple files one by one using javascript. It can be used to simply download files or use it combination with PHP force download. Although javascript opens file in new window, thus forcing open/save dialog box, it might not work in all browsers. So you may want to modify it to link file directly

<p><a id='download' href="" onclick="return download();"></a></p>
<p id='all' style='display:none;'>All files have been downloaded</p>
<script type='text/javascript'>
window.onload = function () 
{ 
    //load files names and path to files into array
    arr = ['documents.zip','document.doc'];
    i = 0;
    document.getElementById("download").innerHTML = 
        'Download ' + (i+1) + '. from ' + arr.length + ' files';
}
function download()
{
    if(i < arr.length)
    {
        window.open(arr[i], 'window'+i, 'width=1, height=1, top=99999, left=99999');
        i++;
        if(i == arr.length)
        {
            document.getElementById("download").disabled = 1;
            document.getElementById("download").style.display = 'none';
            document.getElementById("all").style.display = 'block';
        }
        else
        {
            document.getElementById("download").innerHTML = 
                'Download ' + (i+1) + '. from ' + arr.length + ' files';
        }
    }
    return false;
}
</script>

And here is an example:


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus