Skip to content

Instantly share code, notes, and snippets.

@Anenth
Last active January 19, 2024 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anenth/345bdb56e808ffd3684028242ecba3eb to your computer and use it in GitHub Desktop.
Save Anenth/345bdb56e808ffd3684028242ecba3eb to your computer and use it in GitHub Desktop.
Download all the image in HTML document
function downloadAllImages(container) {
const imageElements = container.querySelectorAll('img');
if (!imageElements.length) {
console.error('No images found in the container.');
return;
}
for (const imageElement of imageElements) {
const imageUrl = imageElement.src;
const filename = imageUrl.split('/').pop();
const linkElement = document.createElement('a');
linkElement.href = imageUrl;
linkElement.download = filename;
linkElement.click();
linkElement.remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment