2013-01-23 25 views
0

多个图像文件我目前正在试图使一个程序,用户可以选择他们想要下载,然后将它们下载,而无需使用任何zip文件每个图像。它目前有效,但它必须为每个链接打开一个新窗口。我想知道是否有人对如何更好的建议做,而无需打开一个窗口,每次下载,而且还比较容易成立?我目前使用从joomlaworks sigpro一个的download.php文件由刚刚指向它在窗口的URL下载方便的解决方案。下载使用jQuery

我的代码:

$('.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); 
      }); 
    }); 

回答

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); 
}); 

然后,您可以清理I帧(例如从DOM中删除),如果你真的想,但你不应该需要。

+0

我不知道为什么我没有想到的是,谢谢!很棒! – fentech