Download link from SVG not working
by stared
HTML
<a id="link_html" download="file.txt">download file (from HTML)</a>
<br/>
<svg height="100" width="300">
<a id="link_svg" download="file.txt">
<text x="0" y="50">download file (from SVG)</text>
</a>
</svg>
JavaScript
var conent = "This is the file content.";
var header = "data:text/plain;charset=utf-8,"
var payload = header + encodeURIComponent(conent);
// works
d3.select("#link_html").on("click", function () {
this.href = payload;
});
// does not work as intended
d3.select("#link_svg").on("click", function () {
//// line below does nothing:
// this["xlink:href"] = payload;
// opens file in the same window, not as a downloaded file!
d3.select("#link_svg").attr("xlink:href", payload);
});