用jQuery下载多个图像文件 [英] Downloading multiple images files with jquery
问题描述
我目前正在尝试制作一个程序,用户可以选择要下载的每个图像,然后不使用任何zip文件就下载它们.它目前可以使用,但是必须为每个链接打开一个新窗口.我想知道是否有人对如何做到这一点有更好的建议,而不必为每次下载打开一个窗口,并且仍然相对容易设置吗?我目前仅通过在窗口URL中指向它,就将joomlaworks sigpro的download.php文件用作简单的下载解决方案.
I'm currently trying to make a program where the user can select each image they want to download then download them without using any zip files. It currently works but it has to open a new window for every link. I was wondering if anybody had a better suggestion on how to do this without opening a window for every download, and is still relatively easy to set up? I'm currently using a download.php file from joomlaworks sigpro as an easy download solution by just pointing to it in the window url.
我的代码:
$('.finishselect').click(function(){
$( ".selected" ).each(function () {
var $href = $(this).parent().children('img').attr('src'),
$hrefShort = $href.replace('http://example.com/plugins/content/gallery/gallery/thumbs/', 'images\\Pics/');
window.open("/plugins/content/jw_sigpro/jw_sigpro/includes/download.php?file=" + $hrefShort);
});
});
推荐答案
您可以使用iframe并将iframe src设置为下载内容.
You could use an iframe and set the iframe src to the download instead.
$( ".selected" ).each(function () {
var $href = $(this).parent().children('img').attr('src'),
$hrefShort = $href.replace('http://example.com/plugins/content/gallery/gallery/thumbs/', 'images\\Pics/');
var $iframe = $('<iframe />');
$iframe.attr('src', "/plugins/content/jw_sigpro/jw_sigpro/includes/download.php?file=" + $hrefShort);
$iframe.css('visibility', 'hidden');
$iframe.css('height', '0');
$iframe.appendTo(document.body);
});
如果您确实愿意,则可以清理iframe(例如,将其从DOM中删除),但不必这样做.
You could then clean up the iframes (e.g. remove them from the DOM) if you really wanted to, but you shouldn't need to.
这篇关于用jQuery下载多个图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!