Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active August 29, 2015 14:15
Show Gist options
  • Save kjbrum/5900f4cee928518a7f12 to your computer and use it in GitHub Desktop.
Save kjbrum/5900f4cee928518a7f12 to your computer and use it in GitHub Desktop.
Save multiple images on a webpage.
function saveFile(url) {
var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(xhr.response);
a.download = filename;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
delete a;
};
xhr.open('GET', url);
xhr.send();
}
// Go through each img tag
$("#container img").each(function() {
saveFile($(this).attr("src"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment