Skip to content

Instantly share code, notes, and snippets.

@sayef
Created May 7, 2021 17:08
Show Gist options
  • Select an option

  • Save sayef/8a28023635fd38233b933b9add399048 to your computer and use it in GitHub Desktop.

Select an option

Save sayef/8a28023635fd38233b933b9add399048 to your computer and use it in GitHub Desktop.
Download SVG Node From HTML
# specify your svg element and run this in chrome console
var svg = document.getElementsByTagName("svg")[0];
var serializedSVG = new XMLSerializer().serializeToString(svg);
var base64Data = window.btoa(serializedSVG);
var dataURL = "data:image/svg+xml;base64," + base64Data
var dl = document.createElement("a");
document.body.appendChild(dl); // This line makes it work in Firefox.
dl.setAttribute("href", dataURL);
dl.setAttribute("download", "test.svg");
dl.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment