Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bookmarklet to download all images on a page
;(function() {
var images = [].slice.call(document.querySelectorAll('img'))
try {
images.forEach(function(img) {
downloadImage(img)
})
} catch (e) {
alert("Download failed.");
console.log('Download failed.', e);
}
function downloadImage(img) {
var link = document.createElement('a')
link.setAttribute('href', img.src)
link.setAttribute('download', '')
link.click()
}
}).call(window);
javascript:;(function() {var images = [].slice.call(document.querySelectorAll('img'));try {images.forEach(function(img){downloadImage(img)})} catch (e) {alert('Download failed.');console.log('Download failed.', e)}function downloadImage(img) {var link = document.createElement('a');link.setAttribute('href', img.src);link.setAttribute('download', '');link.click()}}).call(window);
@lucidBrot

This comment has been minimized.

Copy link

commented Jun 7, 2018

Thx!
Did not work everywhere because of cross-origin loads (https://stackoverflow.com/questions/49474775/chrome-65-blocks-cross-origin-a-download-client-side-workaround-to-force-down) so I created a working version based on your snippet :)

@iyanriana

This comment has been minimized.

Copy link

commented Jun 22, 2018

How to execute this .js file on popup.html? Just trying to implement this into Chrome Extension :)

@lcdsantos1310

This comment has been minimized.

Copy link

commented Sep 30, 2018

Works fine, but some pictures are not included into the download batch. I have to repeat the process several times, getting dup pictures, to the download the full set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.