How to save svg canvas to local filesystem

前端 未结 16 1481
南旧
南旧 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:20

    With FileSaver from Eli Grey I got it working (chrome):

    bb = new window.WebKitBlobBuilder;
    var svg = $('#designpanel').svg('get');
    bb.append(svg.toSVG());
    var blob = bb.getBlob("application/svg+xml;charset=" + svg.characterSet);
    saveAs(blob,"name.svg");
    

    SVG is from keith woods jquery's svg.

    Html Rocks 1

    Html Rocks 2

提交回复
热议问题