-2

Hi i would like to ask if i have a variable in JavaScript that consists of a few image URL links is there anyway to download all of them on window.onload and it will go into my image folder. Is there an easy way to accomplish this any help suggestion would be greatly appreciated thanks.

var test = "https://upload.wikimedia.org/wikipedia/en/thumb/0/09/Circle_Logo.svg/150px-Circle_Logo.svg.png"
Best Jeanist
  • 1,109
  • 4
  • 14
  • 34
  • Ultimately what you want to dO – Ashish sah Jul 31 '18 at 03:46
  • When i go into my html page it will just download all this images to my project folder. – Best Jeanist Jul 31 '18 at 03:48
  • That is not possible on client-side. Pure browser-JavaScript is unable to fetch any information regarding the user file system. – Abhishek Kumar Jul 31 '18 at 03:53
  • @AbhishekKumar impossible to just download image using javascript and getting it into my folder? then what else should i use? – Best Jeanist Jul 31 '18 at 03:55
  • https://stackoverflow.com/questions/17527713/force-browser-to-download-image-files-on-click Look at this – Ashish sah Jul 31 '18 at 03:55
  • @Tommy you can download file from pure javascript, but in the default downloads folder, as javascript ca't access folder structure or file system of any user as it can pose a security threat. You can download the links by just opening each link in browser next tab `window.open(url, '_blank')` – Abhishek Kumar Jul 31 '18 at 03:58

1 Answers1

0

Not Sure What You Want. Maybe This Will Help.

window.onload = () => {
    fetch("https://upload.wikimedia.org/wikipedia/en/thumb/0/09/Circle_Logo.svg/150px-Circle_Logo.svg.png")
        .then((res) => res.blob())
        .then((res) => {
            const img = document.createElement("img")
            img.src = URL.createObjectURL(res)
            document.body.appendChild(img)
        })
}

Fetch API : Fetch API

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Kayac
  • 64
  • 1
  • 8
  • I want to download that image onload and put it in my project folder. – Best Jeanist Jul 31 '18 at 05:04
  • @Tommy Well... I just can't understand. Why you want to download image into "your" project folder. Because when I see the window.onload , I assume you want to create "Client Side Application" not "Server Side Application". – Kayac Aug 12 '18 at 07:21