SVG 다운로드 - ChoDragon9/posts GitHub Wiki
SVG 다운로드
const svgToUrl = svgElement => {
const data = new XMLSerializer().serializeToString(svgElement);
const svg = new Blob([data], {
type: "image/svg+xml;charset=utf-8"
});
return URL.createObjectURL(svg);
};
const downloadFile = (url) => {
const a = Object.assign(document.createElement('a'), {
href: url,
download: true
})
a.click()
}
const svgElement = document.querySelector('svg');
downloadFile(svgToUrl(svgElement));