• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

191
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error