I have a svg-element that I want to export as a SVG and PNG. There are already some approaches here on stack overflow, like this one and the one from mbostock. However, I did something like this:
var $el = '<svg xmlns="http://www.w3.org/2000/svg" height="367" width="780"id="canvas" version="1.1" style="overflow: hidden;">
<circle r="12" style="cursor: move; fill: #4682b4; stroke: #000000; stroke-width: 1.5px;"/></svg>';
var serializer = new XMLSerializer();
var res = serializer.serializeToString($el);
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:image/svg+xml;base64,' + btoa(res);
hiddenElement.download = 'export.svg';
hiddenElement.click();
This does what it should do but only in chrome. Firefox does not react at all and safari tell me this:
Blocked a frame with origin "null" from accessing a frame with origin "http://localhost:8080". The frame requesting access has a protocol of "data", the frame being accessed has a protocol of "http". Protocols must match.
Any suggestions? Thanks.