JavaScript ile LocalStorage Kullanımı

JavaScript ile LocalStorage Kullanımı

LocalStorage, tarayıcıda veri saklamanın en kolay yoludur. Sayfa yenilense bile veriler kaybolmaz!

Temel Kullanim

// (c) CodeMareFi - codemarefi.com.tr

// Veri kaydet
localStorage.setItem('kullanıcı', JSON.stringify({ isim: 'NBK BARIŞ', site: 'CodeMareFi' }));

// Veri oku
const kullanıcı = JSON.parse(localStorage.getItem('kullanıcı'));
console.log(kullanıcı.isim); // NBK BARIS

// Veri sil
localStorage.removeItem('kullanıcı');

// Tum verileri temizle
localStorage.clear();

Tema Tercihi Kaydetme

// (c) CodeMareFi - codemarefi.com.tr
function temaDegistir(tema) {
  localStorage.setItem('tema', tema);
  document.body.className = tema;
}

// Sayfa yuklendiginde temay uygula
const kayitliTema = localStorage.getItem('tema') || 'karanlik';
document.body.className = kayitliTema;
© CodeMareFi Bu içerik codemarefi.com.tr ye aittir.

0 Yorum

YORUM YAPMAK İÇİN SİSTEME SIZMANIZ GEREKİYOR

Lütfen yukarıdaki butonu kullanarak giriş yapın veya kimlik oluşturun.

Yorumlar yükleniyor...