Web Storage API ﺖﺳﺍ ﺮﮔﺭﻭﺮﻣ ﺭﺩ ﺎﻫ ﻩﺩﺍﺩ ﯽﺑﺎﯾﺯﺎﺑ ﻭ ﻩﺮﯿﺧﺫ ﯼﺍﺮﺑ ﻩﺩﺎﺳ ﻮﺤﻧ ﮏﯾ.
localStorage.setItem("name", "John Doe");
localStorage.getItem("name");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
localStorage.setItem("name","John Doe");
document.getElementById("demo").innerHTML = localStorage.getItem("name");
</script>
</body>
</html>
Web Storage API ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ:
Chrome | IE/Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
.ﺪﻨﮐ ﯽﻣ ﻢﻫﺍﺮﻓ ﺹﺎﺧ ﺖﯾﺎﺳ ﺏﻭ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﯽﻠﺤﻣ ﯼﺯﺎﺳ ﻩﺮﯿﺧﺫ ﯼﺎﻀﻓ ﮏﯾ ﻪﺑ ﯽﺳﺮﺘﺳﺩ localStorage ﯽ
.ﺪﻧﻮﺷ ﯽﻤﻧ ﻑﺬﺣ ﺮﮔﺭﻭﺮﻣ ﻥﺪﺷ ﻪﺘﺴﺑ ﺎﺑ ﻭ ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﺎﻀﻘﻧﺍ ﺦﯾﺭﺎﺗ ﻥﻭﺪﺑ ﺎﻫ ﻩﺩﺍﺩ
.ﺩﻮﺑ ﺪﻨﻫﺍﻮﺧ ﺱﺮﺘﺳﺩ ﺭﺩ ﺎﻫ ﻝﺎﺳ ﻭ ﺎﻫ ﻪﺘﻔﻫ ،ﺎﻫﺯﻭﺭ ﯼﺍﺮﺑ ﺎﻫ ﻩﺩﺍﺩ
.ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﻪﻈﻓﺎﺣ ﮏﯾ ﺭﺩ ﺍﺭ ﻩﺩﺍﺩ ﻢﺘﯾﺁ ﮏﯾ()localStorage.setItem ﺪﺘﻣ
:ﺩﺮﯿﮔ ﯽﻣ ﺮﺘﻣﺍﺭﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ ﺭﺍﺪﻘﻣ ﮏﯾ ﻭ ﻡﺎﻧ ﮏﯾ
localStorage.setItem("name", "John Doe");
.ﺪﻨﮐ ﯽﻣ ﯽﺑﺎﯾﺯﺎﺑ ﻪﻈﻓﺎﺣ ﺯﺍ ﺍﺭ ﻩﺩﺍﺩ ﻢﺘﯾﺁ ﮏﯾ()localStorage.getItem ﺪﺘﻣ
:ﺩﺮﯿﮔ ﯽﻣ ﺮﺘﻣﺍﺭﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ ﻡﺎﻧ ﮏﯾ
localStorage.getItem("name");
.ﺖﺳﺍ ﻥﺎﺴﮑﯾ localStorage ﯽﺷ ﺎﺑ sessionStorage ﯽﺷ
.ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﻪﺴﻠﺟ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﺎﻫ ﻩﺩﺍﺩ sessionStorage ﯽﺷ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﺕﻭﺎﻔﺗ
.ﺪﻧﻮﺷ ﯽﻣ ﻑﺬﺣ ﺎﻫ ﻩﺩﺍﺩ ﺮﮔﺭﻭﺮﻣ ﻥﺪﺷ ﻪﺘﺴﺑ ﺎﺑ
sessionStorage.getItem("name");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
sessionStorage.setItem("name","John Doe");
document.getElementById("demo").innerHTML = sessionStorage.getItem("name");
</script>
</body>
</html>
.ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﻪﻈﻓﺎﺣ ﮏﯾ ﺭﺩ ﺍﺭ ﻩﺩﺍﺩ ﻢﺘﯾﺁ ﮏﯾ()sessionStorage.setItem ﺪﺘﻣ
:ﺩﺮﯿﮔ ﯽﻣ ﺮﺘﻣﺍﺭﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ ﺭﺍﺪﻘﻣ ﮏﯾ ﻭ ﻡﺎﻧ ﮏﯾ
sessionStorage.setItem("name", "John Doe");
.ﺪﻨﮐ ﯽﻣ ﯽﺑﺎﯾﺯﺎﺑ ﻪﻈﻓﺎﺣ ﺯﺍ ﺍﺭ ﻩﺩﺍﺩ ﻢﺘﯾﺁ ﮏﯾ()sessionStorage.getItem ﺪﺘﻣ
:ﺩﺮﯿﮔ ﯽﻣ ﺮﺘﻣﺍﺭﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ ﻡﺎﻧ ﮏﯾ
sessionStorage.getItem("name");
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻪﻈﻓﺎﺣ ﺭﺩ ﻡﺍn ﺪﯿﻠﮐ ﻡﺎﻧ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ Storage ﯽﺷ ﺭﺩ ﻩﺪﺷ ﻩﺮﯿﺧﺫ ﻩﺩﺍﺩ ﻡﻼﻗﺍ ﺩﺍﺪﻌﺗ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺷ ﺺﺨﺸﻣ ﺪﯿﻠﮐ ﻡﺎﻧ ﺭﺍﺪﻘﻣ
(ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﻞﺒﻗ ﺯﺍ ﺮﮔﺍ) ﺪﻨﮐ ﯽﻣ ﺯﻭﺭ ﻪﺑ ﺍﺭ ﺪﯿﻠﮐ ﺭﺍﺪﻘﻣ ﮏﯾ ﺎﯾ ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﯼﺯﺎﺳ ﻩﺮﯿﺧ
ﺪﻨﮐ ﯽﻣ ﺝﺭﺎﺧ ﻪﻈﻓﺎﺣ ﺯﺍ ﺍﺭ ﺪﯿﻠﮐ ﻥﺁ
ﺪﯿﻨﮐ ﯽﻟﺎﺧ ﯼﺯﺎﺳ ﻩﺮﯿﺧﺫ ﯼﺎﻀﻓ ﺯﺍ ﺍﺭ ﺪﯿﻠﮐ ﻡﺎﻤﺗ
ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﻩﺭﺎﻤﺷ ﺎﺑ ﺍﺭ ﺎﻫ ﻩﺩﺍﺩ .ﺪﻨﮐ ﯽﻣ ﻢﻫﺍﺮﻓ ﺍﺭ ﺏﻭ ﺮﮔﺭﻭﺮﻣ ﺭﺩ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﯼﺎﻫ ﺖﻔﺟ ﻩﺮﯿ
ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﺎﻫ ﻩﺩﺍﺩ .ﺪﻨﮐ ﯽﻣ ﻢﻫﺍﺮﻓ ﺍﺭ ﺏﻭ ﺮﮔﺭﻭﺮﻣ ﺭﺩ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﯼﺎﻫ ﺖﻔﺟ ﻩﺮﯿﺧ