How to save svg canvas to local filesystem

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

    It might be possible using the regular "Save" browser command, but it won't just save the SVG canvas, it will save the whole page.

    I believe your best bet is to use AJAX and send the whole SVG XML data as POST data to a server script, and have that script just send back the POST data with the header Content-Disposition: attachment; filename=yourfile.svg.

    (Under PHP, you can get the raw POST contents with file_get_contents('php://input').)

提交回复
热议问题