How to save svg canvas to local filesystem

前端 未结 16 1434
南旧
南旧 2020-11-27 10:10

Is there a way to allow a user, after he has created a vector graph on a javascript svg canvas using a browser, to download this file to their local filesystem?

SVG

16条回答
  •  自闭症患者
    2020-11-27 10:32

    	// save SVG
    	$('#SVGsave').click(function(){
    		var a      = document.createElement('a');
    		a.href     = 'data:image/svg+xml;utf8,' + unescape($('#SVG')[0].outerHTML);
    		a.download = 'plot.svg';
    		a.target   = '_blank';
    		document.body.appendChild(a); a.click(); document.body.removeChild(a);
    	});

提交回复
热议问题