简体   繁体   中英

Force Download Images with Javascript

I have a list of public links of Google streetview images similar to this

" https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4 "

I want to automate downloading of these image files to my computer using Javascript. Is there any Javascript library I can use for this task?

For a download link you can use a link with the "download" attribute (from here ):

<a href="https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4" download>Download</a>

For an automatic download you can use a script (from here ):

<script type="text/javascript">
    var link = document.createElement('a');
    link.href = 'https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4';
    link.download = 'Download.jpg';
    document.body.appendChild(link);
    link.click();
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM