6

I'm trying to export an HTML5 canvas as a PNG file, so that it is stored on the user's computer.

The following snippet saves the image correctly.

document.location.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");

However using Chrome on Mac OS X, it always is saved as "download". In Safari it is called "Unknown". Firefox gives it a gobbledygook name.

Can I suggest to the browser a name to use, such as "exportedImage.png"?

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184

1 Answers1

4

This is apparently a topic of discussion in browser bug lists and a W3C mailing list. I can't find any evidence that any browser supports the idea of a filename parameter in a "data:" URL, though it is clear that the spec supports the idea of parameters in general.

Also see this older SO question, which is essentially the same as this one.

Community
  • 1
  • 1
Pointy
  • 405,095
  • 59
  • 585
  • 614