0

If I click that Download All I need to download all that image to my local system

<div>
  <img src='image1.jpg'/>
  <img src='image2.jpg'/>
  <img src='image3.jpg'/>
  <button> Download All </button>
</div>

Give me some solution for this

Pravin
  • 441
  • 2
  • 8
  • 26
  • 1
    Please explain what you have tried without success rather than asking for a solution to your problem. – Guy Jul 04 '15 at 11:21

3 Answers3

3

If you want to download without zipped them, you can use a javascript function like this to download one to one:

function downloadWithName(uri, name) {
    function eventFire(el, etype){
        if (el.fireEvent) {
            (el.fireEvent('on' + etype));
        } else {
            var evObj = document.createEvent('MouseEvent');
            evObj.initMouseEvent(etype, true, false, 
                 window, 0,
                 0, 0, 0, 0,
                 false, false, false, false,
                 0, null);
            el.dispatchEvent(evObj);
        }
    }

    var link = document.createElement("a");
    link.download = name;
    link.href = uri;
    eventFire(link, "click");
}

But, you need to make some changes in your code in order to allow to download all images with a single click. In your case, this code will run ;)

<div id="allImages">
  <img src='image1.jpg' />
  <img src='image2.jpg' />
  <img src='image3.jpg' />
  <button onclick="downloadAll()"> Download All </button>
</div>

<script>
function downloadAll(){
    var div = document.getElementById("allImages");
    console.log(div);
    var images = div.getElementsByTagName("img");
    console.log(images)

    for(i=0; i<images.length ; i++){
        console.log(images[i]);
        downloadWithName(images[i].src,images[i].src);
    }
}

function downloadWithName(uri, name) {
    function eventFire(el, etype){
        if (el.fireEvent) {
            (el.fireEvent('on' + etype));
        } else {
            var evObj = document.createEvent('MouseEvent');
            evObj.initMouseEvent(etype, true, false, 
                 window, 0, 0, 0, 0, 0,
                 false, false, false, false,
                 0, null);
            el.dispatchEvent(evObj);
        }
    }

    var link = document.createElement("a");
    link.download = name;
    link.href = uri;
    eventFire(link, "click");
}
</script>

As you can imagine, you can add more <img> inside <div id="allImages"> and user will download all together.

Aerogirl
  • 369
  • 4
  • 17
EnriMR
  • 3,924
  • 5
  • 39
  • 59
  • Its working in chrome,But its not working in mozilla – Pravin Jul 04 '15 at 11:55
  • 1
    I have fixed for Firefox ;) In downloadWithName > eventFire you have to use initMouseEvent instead of initEvent. I have edited my answer, try it! – EnriMR Jul 04 '15 at 12:32
0

HTTP does not support more than one file download at once.

There are two solutions:

  • Open any amount of windows to initiate the file downloads (using JavaScript)
  • Create a script to zip the file.

You could use try scripts from this link for more options.

Community
  • 1
  • 1
Abey
  • 1,408
  • 11
  • 26
-3

You can just left click on the website and select 'Save as..' (in Chrome) / 'save page as' (in Firefox). You will get all the images in that page in a folder. You do not have to use any scripts or any CLI.

Tomasz
  • 4,847
  • 2
  • 32
  • 41
lulu
  • 191
  • 1
  • 7