Created
April 23, 2023 14:18
-
-
Save ByK95/8547e799478b76cccc06d88e9bcfbe86 to your computer and use it in GitHub Desktop.
download svg from html svg view as 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
const svg = document.getElementById('svg_null'); | |
// Get the XML content of the SVG | |
const svgData = new XMLSerializer().serializeToString(svg); | |
// Create a new Blob object from the SVG data | |
const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); | |
// Create a new URL object from the Blob | |
const url = URL.createObjectURL(blob); | |
// Create a new link element and set its properties | |
const link = document.createElement('a'); | |
link.href = url; | |
link.download = 'image.svg'; | |
// Click the link to download the file | |
link.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment