4

I am working with javascript + Raphael.js and would like to export the paper with JSON and download it as a text file by clicking a button.

I have already managed to export the paper with JSON due to raphael.json.js and save it as a string:

var json = paper.toJSON();

and I have also found something to download it as a text file:

var a = document.body.appendChild(
            document.createElement("a")
    );
    a.download = "export.txt";
    a.href = "data:text/plain;base64," + btoa(json);
    a.innerHTML = "download example text";

but unfortunately only by creating a link instead of clicking a button and I have no idea how to manage that.

Thank you in advance!

hedge
  • 41
  • 1
  • 4
  • somebody answered here: [Javascript set file in download](http://stackoverflow.com/questions/16376161/javascript-set-file-in-download) – Justin Feb 03 '16 at 01:55
  • This library is really good at doing that: https://github.com/eligrey/FileSaver.js/. I've been using it for a while – Mr. Duc Nguyen Feb 03 '16 at 04:29

0 Answers0