getfile.js 614 B

123456789101112131415161718192021222324
  1. function test(text)
  2. {
  3. //alert("Testing private key export!!");
  4. download("GFG.json", text);
  5. return "111";
  6. }
  7. function download(file, text) {
  8. //creating an invisible element
  9. var element = document.createElement('a');
  10. element.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(text));
  11. element.setAttribute('download', file);
  12. // Above code is equivalent to
  13. // <a href="path of file" download="file name">
  14. document.body.appendChild(element);
  15. //onClick property
  16. element.click();
  17. document.body.removeChild(element);
  18. }