lundi 7 décembre 2020

Save / Load check box state in cookie

Having a page with articles where each article is composed of PHOTO, TITLE and DESCRIPTION. And 4 checkboxes :

  1. ID="cb-pic" : allow user to show/hide PHOTOs from articles,
  2. ID="cb-line" : display articles in linear layout
  3. ID="cb-box" : display articles in boxes mode
  4. ID="cb_dark" : switch from dark to light mode

I have 3 question about this, assuming i want the preferences to be saved permanently until the user clear browser history of course :

  • Which the method that's fit the best this : LocalStorage or Cookies ?
  • How to save / load or read / write these "boolean" data ?
  • For each checkbox onclick i already have a function that apply corresponding styles changes, So ! when loading the checkbox state, how to run the corresponding script so the changes apply automatically when cookies load ?

PS : As a beginner in web development and never dealed with cookie before it would great if detailed explanation is provided, Thanks a lot guys.




Aucun commentaire:

Enregistrer un commentaire