1var fileContents = "Hello world!";
2var filename = "hello.txt";
3var filetype = "text/plain";
4
5var a = document.createElement("a");
6dataURI = "data:" + filetype +
7 ";base64," + btoa(fileContents);
8a.href = dataURI;
9a['download'] = filename;
10var e = document.createEvent("MouseEvents");
11// Use of deprecated function to satisfy TypeScript.
12e.initMouseEvent("click", true, false,
13 document.defaultView, 0, 0, 0, 0, 0,
14 false, false, false, false, 0, null);
15a.dispatchEvent(e);
16a.removeNode();
17