I know there have been similar topics, but I haven't found exactly what I am looking for.
The requirement is, to generate and download a file with a given name and extension when clicking on an element (e.g. button). Generating this file is expensive to compute, so I cannot compute it beforehand and add it to the href attribute of a link/<a>
, like proposed in many answers.
For example in this fiddle
var obj = {a: 123, b: "4 5 6"};
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(obj));
$('<a href="data:' + data + '" download="data.json">download JSON</a>').appendTo('#container');
I also found this answer, but apparently it is not possible to specify a filename here.
So I was wondering if this is even possible or might be forbidden due to security limitations (would make sense)?