我目前正在尝试创建一个程序,用户可以选择要下载的每个图像,然后在不使用任何zip文件的情况下下载它们。它目前有效,但它必须为每个链接打开一个新窗口。我想知道是否有人在没有为每次下载打开一个窗口的情况下有更好的建议如何做到这一点,并且仍然相对容易设置?我目前正在使用joomlaworks sigpro的download.php文件作为一个简单的下载解决方案,只需在窗口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);
});
});
答案 0 :(得分:1)
您可以使用iframe并将iframe src设置为下载。
$( ".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中删除它们),如果你真的想要,但你不应该这样做。