Last active
August 29, 2015 14:15
-
-
Save kjbrum/5900f4cee928518a7f12 to your computer and use it in GitHub Desktop.
Save multiple images on a webpage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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