单击按钮时,如何让用户下载多个文件? [英] How can I let a user download multiple files when a button is clicked?
问题描述
所以我有一个 httpd 服务器正在运行,它有一堆文件的链接.假设用户从文件列表中选择三个文件进行下载,它们位于:
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:
mysite.com/file1
mysite.com/file2
mysite.com/file3
当他们点击下载按钮时,我希望他们从上面的链接下载这三个文件.
When they click the download button I want them to download these three files from the links above.
我的下载按钮看起来像:
My download button looks something like:
var downloadButton = new Ext.Button({
text: "Download",
handler: function(){
//download the three files here
}
});
推荐答案
最好的方法是将文件压缩并链接到该文件:
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
声明如下:
HTML:
<a href="#" class="yourlink">Download</a>
JS:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('mysite.com/file1');
window.open('mysite.com/file2');
window.open('mysite.com/file3');
});
话虽如此,我仍然会压缩文件,因为这个实现需要 JavaScript,有时也可以作为弹出窗口被阻止.
Having said this, I would still go with zipping the file, as this implementation requires JavaScript and can also sometimes be blocked as popups.
这篇关于单击按钮时,如何让用户下载多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!