• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

190
Vistas
Saving HTML data Client-side

If I assign a text input tag to the id stored_data1 in the code below, would I be able to save my data client-side (such as saving it on a flash drive)?

HTML

Data that is retrieved will appear here
<div id="dataStore"></div>

JS

<script>
  if (typeof Storage !== 'undefined') {
    localStorage.setItem('stored_data1', 'Blue Box');
    document.getElementById('dataStore').innerHTML =
      localStorage.getItem('stored_data1');
  } else {
    // in case web storage is not supported
    document.getElementById('dataStore').innerHTML =
      'Web storage not supported.';
  }
</script>

The code above is a web storage API for HTML. I'm hoping to find a way to eventually fit it into some programs I made.

about 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can download the information on the tag using the following code

//create a function to download text to textfile
function downloadText(text, filename){
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);
  element.style.display = 'none';
  document.body.appendChild(element);
  element.click();
}


//get Text Value then download 
var textValue = document.getElementById("test").innerText;
download(textValue, "store_data");
about 3 years ago · Juan Pablo Isaza Denunciar

0

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<p>Data that is retrieved will appear here</p>
<div id="dataStore"></div>
</body>
    <script>
    if (typeof(Storage) !== "undefined") {
      window.localStorage.setItem("stored_data1", "Blue Box");
      document.getElementById("dataStore").innerHTML = window.localStorage.getItem("stored_data1");
    } else {
      document.getElementById("dataStore").innerHTML = "Web storage not supported.";
    }
</script>
</html> 
about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda