Last active
January 19, 2024 15:44
-
-
Save Anenth/345bdb56e808ffd3684028242ecba3eb to your computer and use it in GitHub Desktop.
Download all the image in HTML document
This file contains 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 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