单击按钮时,如何让用户下载多个文件? [英] How can I let a user download multiple files when a button is clicked?
问题描述
所以我有一个运行httpd服务器的链接到一堆文件。假设用户从文件列表中选择三个文件进行下载,它们位于:
mysite.com/file1
mysite.com/file2
mysite.com/file3
当他们点击下载按钮我希望他们从上面的链接下载这三个文件。
我的下载按钮看起来像:
var downloadButton = new Ext.Button({
text:Download,
handler:function(){
//在这里下载三个文件
}
});
最好的方式是让你的文件压缩并链接到:
另一个解决方案可以在这里找到:如何使链接在单击时打开多个页面
哪些说明以下内容:
HTML:
< a href =#类= yourlink >下载及LT; / A>
JS:
code $('a.yourlink')点击(function(e){
e.preventDefault();
window.open('mysite.com/file1');
window.open('mysite.com/file2');
window.open('mysite.com/file3');
});说到这一点,我仍然会去压缩文件,因为这个实现需要JavaScript,也可以有时被阻止为弹出窗口。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
Which states the following:
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'); });
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屋!