Steve McLeod
Steve McLeod

Reputation: 52448

When using document.location.href to save client-side data, how can I suggest a filename to the browser?

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"?

Upvotes: 6

Views: 4333

Answers (1)

Pointy
Pointy

Reputation: 413692

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.

Upvotes: 4

Related Questions