Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

local storage

function setItem(name, value) {
  localStorage.setItem(name, value);
}
function getItem(name) {
  localStorage.getItem(name);
}
function deletItem(name) {
  localStorage.removeItem(name);
}
function clearStorage() {
  localStorage.clear();
}
Comment

local storage ha


function set(){
    var sendJson = JSON.stringify(allPerfume);
    localStorage.setItem("allPerfume", sendJson);
}

function get() {
    var getJson = localStorage.getItem("allPerfume")
    if (getJson) {
        allPerfume = JSON.parse(getJson);
    }
}
Comment

local storage

As the answers here already talk about the coding aspect. I will talk about
the concept.
Local storage is basically an object stored in the specific browser you are 
using in that moment. And thus it is tied to that browser in that device. It's 
duration is infinite so it never expires

If you only want to store data that only lasts for that browser session(
starts when you open a window and ends when you close it) then the best choice
is sessionStorage
Comment

local storage

localStorage.setItem('localStorage', 1);
Comment

local storage

<form action="2.html" onsubmit="callme()">
    <p>Enter your name</p>
    <input id="tbName" type="text">
    <button type="submit" value="submit">Submit</button>
</form>
<script>
    function callme(){
        var name = document.getElementById('tbName').value;
        sessionStorage.setItem('userName', name);
    }
</script>
Comment

local storage

window.localStorage.setItem("grade","One");
//in this case, the `grade` is the key while `One` is the value.
Comment

Local Storage

<script>
  //an immediately invoked function that checks to see if the text is in local storage already
  (function(){
    //if the text is in local storage, set the html
    if (localStorage.currentTotal){
    console.log(localStorage.currentTotal);
    document.getElementById('class').innerHTML = localStorage.getItem("currentTotal");
  }
    })();
  //function that gets called for an onclick event
  function myFunction() {
// Store in local storage
localStorage.setItem("currentTotal", "Class current balance total");
//set the inner html to what is in local storage
document.getElementById("class").innerHTML = localStorage.getItem("currentTotal");

}
</script>
Comment

local storage

var answer = localStorage.key(1);
// this statement will retrieve the value of the second item in localStorage.
Comment

local storage

window.localStorage.getItem("key");
Comment

PREVIOUS NEXT
Code Example
Javascript :: disable scroll on modal open 
Javascript :: javascript minimum number in array 
Javascript :: jquery thousand separator 
Javascript :: date js 
Javascript :: Sort number in descending order 
Javascript :: nested for loop javascript 
Javascript :: open modal in jqwuery 
Javascript :: reactjs make main div scrollable 
Javascript :: javascript date is an object 
Javascript :: dynamic select option dropdown in jquery 
Javascript :: hot reload problem react 17 
Javascript :: how to hash with crypto Node.js 
Javascript :: fetch api javascript 
Javascript :: lodash angular 9 
Javascript :: how to set background colour i js inline stylel 
Javascript :: how to stop browser back js history.pushState 
Javascript :: To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. 
Javascript :: javascript allow only numeric characters 
Javascript :: javascript change paragraph text 
Javascript :: javascript string contains character 
Javascript :: javascript origin url 
Javascript :: jquery check checkbox 
Javascript :: js conditional key 
Javascript :: lwc quick action close 
Javascript :: add css on click javascript 
Javascript :: moment js from now 
Javascript :: javascript hide and show 
Javascript :: jquery toggleclass 
Javascript :: click on a radio button using jquery 
Javascript :: concat object 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =