blob: d3597e77749daab1afb9bbe2e1d7f986556b2369 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
let download filename content =
let a =
H.a
[| HA.href ("data:text/plain;charset=utf-8," ^ URI.encode content)
; HA.download filename
; HA.style "display:none"
|]
[| |]
in
let () = Element.append_child Document.body a in
let () = Element.click a in
Element.remove_child Document.body a
external reader : unit -> Dom.element = "FileReader"
[@@bs.new]
external read_as_text : Dom.element -> string -> unit = "readAsText"
[@@bs.send]
external result : Dom.element -> string = "result"
[@@bs.get]
|