Custom Web Storage methods by using cookie. You can set/get/search/remove key value pair by simply calling inbuilt methods.
Clone/Download a script1.js file to your root directory.
Link this script to index.html
MyStorage object is available globaly which have three usefull methods
- setItem()
- getItem()
- removeItem()
- MyStorage.setItem(key,value)
- Take key value pair
- Store this pair to cookie
- If key already exists return FALSE
- Otherwise return TRUE
- MyStorage.getItem(key)
- Take a key
- Search value by key
- If value found return Value (string)
- Otherwise return FALSE
- MyStorage.removeItem(key)
- Take a key
- Search value by key
- If value found, remove it and return TRUE
- Otherwise return FALSE
-
Store red color hex code
MyStorage.setItem('red','#ff0000')
-
Retrive hex code color name
MyStorage.getItem('red')
-
Remove red color
MyStorage.removeItem('red')