How can I let a user download multiple files when a button is clicked?

前端 未结 9 1078
不知归路
不知归路 2020-11-27 18:18

So I have a httpd server running which has links to a bunch of files. Lets say the user selects three files from a file list to download and they\'re located at:

         


        
9条回答
  •  北海茫月
    2020-11-27 19:08

    The best way to do this is to have your files zipped and link to that:

    The other solution can be found here: How to make a link open multiple pages when clicked

    Which states the following:

    HTML:

    Download
    

    JS:

    $('a.yourlink').click(function(e) {
        e.preventDefault();
        window.open('mysite.com/file1');
        window.open('mysite.com/file2');
        window.open('mysite.com/file3');
    });
    

    Having said this, I would still go with zipping the file, as this implementation requires JavaScript and can also sometimes be blocked as popups.

提交回复
热议问题