Preciso criar um arquivo texto no celular com javascript
Este é o meu HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Local
</title>
<link rel="stylesheet" type="text/css" href="css/index.css"></link>
<script language="javascript" type="text/javascript" src="js/index.js"></script>
</head>
<body>
<div class="pag">
<form name="flocal">
<p>
<h2>Local</h2>
</p>
<p id="plocal">
CEP <br><input type="text" name="cep" id="icep" onkeypress='return RestringeNum(event)' maxlength="8" autofocus><br><br>
Rua <br><input type="text" name="rua" id="irua" onkeypress='return RestringeLet(event)'><br><br>
Número <br><input type="text" name="numero" id="inum" onkeypress='return RestringeNum(event)' maxlength="4"><br><br>
Bairro <br><input type="text" name="bairro" id="ibai" onkeypress='return RestringeLet(event)'><br><br>
Complemento <br><input type="text" name="complemento" id="icom"><br><br>
São Vicente-SP<br><br>
<button onclick="SalvarDados()">Salvar dados</button>
</p>
</form>
</div>
</body>
</html>
e este é o meu js:
function RestringeNum(e)
{
var tecla = (window.event)?event.keyCode:e.which;
if((tecla>47 && tecla<58)) return true;
else
{
if (tecla==8 || tecla==0) return true;
else return false;
}
}
function RestringeLet(e){
var tecla = (window.event)?event.keyCode:e.which;
if ((tecla > 64 && tecla < 91) || (tecla > 96 && tecla < 123) || (tecla == 32) || (tecla == 186)) return true;
else return false;
}
function SalvarDados(){
var dados = document.getElementById("icep").value + " - "
+ document.getElementById("irua").value + " - "
+ document.getElementById("inum").value + " - "
+ document.getElementById("ibai").value + " - "
+ document.getElementById("icom").value;
var textFileAsBlob = new Blob([dados], {type:'text/plain'});
var nome_arquivo = "formLocal";
var downloadLink = document.createElement("a");
downloadLink.download = nome_arquivo;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null)
{
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else
{
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
Funciona normalmente no meu pc, mas quando passo para o meu celular(usando o cordova), e clico no botão, que supostamente deveria criar um arquivo texto com o que eu digitei nos inputs, todos os inputs são "limpados", mas aparentemente não acontece nada.
Discussão (2)
Carregando comentários...