Skip to content

Instantly share code, notes, and snippets.

@ByK95
Created April 23, 2023 14:18
Show Gist options
  • Save ByK95/8547e799478b76cccc06d88e9bcfbe86 to your computer and use it in GitHub Desktop.
Save ByK95/8547e799478b76cccc06d88e9bcfbe86 to your computer and use it in GitHub Desktop.
download svg from html svg view as document
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