Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

Downloading multiple images files with jquery

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.

my code:

$('.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);
            });
    });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...