[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/API/Storage [Back]  [Original]

Storage - Web API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Storage

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Web Storage API Storage .

Window.sessionStorage, Window.localStorage .

In this article

Storage.length

Storage .

Storage.key()

n n .

Storage.getItem()

.

Storage.setItem()

. .

Storage.removeItem()

.

Storage.clear()

.

localStorage Storage . !localStorage.getItem('bgcolor') . Storage.getItem() setStyles() . populateStorage() , Storage.setItem() . setStyles() .

js
if (!localStorage.getItem("bgcolor")) {
  populateStorage();
} else {
  setStyles();
}

function populateStorage() {
  localStorage.setItem("bgcolor", document.getElementById("bgcolor").value);
  localStorage.setItem("font", document.getElementById("font").value);
  localStorage.setItem("image", document.getElementById("image").value);
}

function setStyles() {
  var currentColor = localStorage.getItem("bgcolor");
  var currentFont = localStorage.getItem("font");
  var currentImage = localStorage.getItem("image");

  document.getElementById("bgcolor").value = currentColor;
  document.getElementById("font").value = currentFont;
  document.getElementById("image").value = currentImage;

  htmlElem.style.backgroundColor = "#" + currentColor;
  pElem.style.fontFamily = currentFont;
  imgElem.setAttribute("src", currentImage);
}

Specification
HTML
# storage


Web Proxy Viewer  |  New URL  |  Original Page