forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-file.js
More file actions
35 lines (29 loc) · 772 Bytes
/
export-file.js
File metadata and controls
35 lines (29 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function clean (link) {
// allow time for iOS
setTimeout(() => {
window.URL.revokeObjectURL(link.href)
}, 10000)
link.remove()
}
export default function (fileName, rawData, mimeType) {
const blob = new Blob([ rawData ], { type: mimeType || 'text/plain' })
// IE11 has its own stuff...
if (window.navigator.msSaveOrOpenBlob) {
return window.navigator.msSaveOrOpenBlob(blob, fileName)
}
const link = document.createElement('a')
link.download = fileName
link.href = window.URL.createObjectURL(blob)
link.classList.add('hidden')
link.style.position = 'fixed' // avoid scrolling to bottom
document.body.appendChild(link)
try {
link.click()
clean(link)
return true
}
catch (err) {
clean(link)
return err
}
}