Question: I'm a beginner with JS and HTML.
I'm working on a certain project to generate pie charts, I am using google charts with an HTML API.

I managed to produce the chart and get the image URL.
That when I call this line:
`window.open(URL);`
a new window is opened containing the picture.
My question is, is there a similar type method that takes the URL and downloads the image in the project folder?
something like `download(URL,'PNG');` or even `download(URL);`?

Answer: 
See this question if you're trying to allow the end user to download that image: 
[Download image with JavaScript](https://stackoverflow.com/questions/17311645/download-image-with-javascript)

If you're trying to download the image for use in the page, why not use an tag and reference it remotely?

```
    <img src="[url retrieved from the api]">

```

Keep in mind that Javascript is run on the client side, so any download functions would download to the end user, not the project folder.

**EDIT: Made a fiddle with the code used and made an implementation.**

[The fiddle](https://jsfiddle.net/f427z2ny/2/). 

I pulled from the Google Chart docs "[Printing PNGs](https://developers.google.com/chart/interactive/docs/printing#overview)". Here's how they did it:

```
//Your data and options initialization up here 
....

//Event listener
google.visualization.events.addListener(chart, 'ready', function () {
    chart_div.innerHTML = '<img src="' + chart.getImageURI() + '" download="chart.png">';
    console.log(chart_div.innerHTML);
}); 

//Actually draw the chart
chart.draw(data, options);

```

Just use the other SO link to complete the download procedure!
Read this article <http://pixelscommander.com/en/javascript/javascript-file-download-ignore-content-type/> (you can see working here <http://codepen.io/jelmerdemaat/pen/brjKG?editors=0010>)

You can call `downloadFile(URL);` the user can choose where him will save the image