Name a PNG file saved from Canvas using an “open with” dialog

后端 未结 3 620
醉酒成梦
醉酒成梦 2020-12-09 12:42

I am working with canvas and I would be able to save my Canvas to png.

By looking around, I discover the great toDataURL() function given by the W3C.

I am al

相关标签:
3条回答
  • 2020-12-09 13:10

    Unfortunately not. Currently data URIs (used by that canvas2image module; quite neat, actually) do not support specifying filename or content-disposition headers, so the only way to force the browser to generate a save as dialog is to set the content-type to octet-stream.

    0 讨论(0)
  • 2020-12-09 13:15

    Well, in the real world web applications Hangrui Gao's solution is far from acceptable, according to

    http://caniuse.com/#feat=download

    you'll deny this feature to all IE, Safari, IOS Safari, Android's users.

    I think that given this limit in Canvas2Image, a better solution is to use some server side logic as explained here

    Linuxatico

    0 讨论(0)
  • 2020-12-09 13:20

    if you aim to only modern browsers and don't care cross-browser that much, there's a possible solution with "download" attribute of element. Here's one sample for your information:

    <a target="_blank" href="https://www.google.com/intl/en_com/images/srpr/logo3w.png" download="testXXX.jpg">DOWNLOAD ME!</a>
    

    Only one line, no javascript, yeah! You can change the href part into data url, and that works too.

    Check this Eric's tutorial on html5rocks for more details.

    0 讨论(0)
提交回复
热议问题