7

I generate an SVG string in JavaScript.

I serve it to the user with:

window.open("data:image/svg+xml," + svg_xml_string);

When you try to save that page in Chrome it will suggest to save as download.svg is there anyway I can change the default filename of the download?


I tried:

data:image/svg+xml;headers=Content-Disposition%3Aattachment%3Bfilename%3D%22suggest.svg%22,...

But it doesn't work.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
  • Related: http://stackoverflow.com/questions/283956/is-there-any-way-to-specify-a-suggested-filename-when-using-data-uri (unresolved) – Halcyon Jan 16 '13 at 12:25
  • 1
    Also: http://en.wikipedia.org/wiki/Data_URI_scheme#Disadvantages _"Data URIs do not carry a filename as a normal linked file would. When saving, a default filename for the specified MIME type is generally used."_ – Halcyon Jan 16 '13 at 12:34

1 Answers1

-1

This is solved in some, very new browsers. The question linked in the comments also mentions the Opera-specific proposed extension you brought up, but I think your best bet is to use the <a download="..."> attribute and suggest that users with older browsers set the filename for themselves when downloading.

Coderer
  • 25,844
  • 28
  • 99
  • 154