0

I want to create a file in javascript. Before you say that it is impossible, go read this answer.

Here is what I have so far :

window.open("data:text/json;charset=utf-8," + escape("Ur String Object goes here"));

Now, my question is : How do I give a name to this file?

Community
  • 1
  • 1
Gudradain
  • 4,653
  • 2
  • 31
  • 40

1 Answers1

1

You don't; data URIs don't have a filename:

http://en.wikipedia.org/wiki/Data_URI_scheme#Disadvantages

You can link to it and use the download attribute, though:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

FWIW, you're not really creating a file here.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302