Hello, i made a website ( https://sky-music.herokuapp.com/ ) and i was trying to turn it into a super simple app for android, i managed to get everything to work correctly, including the input and account system, but how can i make the site download a file?, i use this inside the website to download the file:
function downloadJSON(inArray, fileName) {
var json = JSON.stringify(inArray)
//Convert JSON string to BLOB.
json = [json]
var blob1 = new Blob(json, {
type: "text/plain;charset=utf-8"
})
//Check the Browser.
let isIE = false || !!document.documentMode
if(isIE) {
window.navigator.msSaveBlob(blob1, fileName)
}else{
let url = window.URL || window.webkitURL
link = url.createObjectURL(blob1)
let a = document.createElement("a")
a.download = fileName
a.href = link
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}
}
it does work on the website (opened trough a browser) but it doesnt work when the website is inside the webviewer in the app, is there a way i can fix it? (the file is generated locally, it’s not in a server)
EDIT: i changed download method to this one:
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(inArray));
var dlAnchorElem = document.createElement("a")
dlAnchorElem.setAttribute("href", dataStr );
dlAnchorElem.setAttribute("download", fileName+".txt");
dlAnchorElem.click();
dlAnchorElem.remove()
This gives me the URL encoded json, how can i convert that back to a json and download the text as a file.txt?