将SVG内容下载为PNG文件,以下代码在Chrome中工作正常,但在IE浏览器中无法正常工作。有什么建议吗?
var svg = document.querySelector( "svg" );
var svgData = new XMLSerializer().serializeToString( svg );
var canvas = document.createElement( "canvas" );
var svgSize = svg.getBoundingClientRect();
canvas.width = svgSize.width;
canvas.height = svgSize.height;
var ctx = canvas.getContext( "2d" );
var img = document.createElement( "img" );
img.setAttribute( "src", "data:image/svg+xml;base64," + btoa( svgData ) );
img.onload = function() {
ctx.drawImage( img, 0, 0 );
setTimeout(function(){
var a = document.createElement("a");
a.download = "networkmap.png";
a.href = canvas.toDataURL("image/png");console.log(a.href);
a.click();
}, 500);
};
答案 0 :(得分:0)
data:image/svg+xml;
似乎很可疑,data:image/png
是PNG的正确Mime类型。