API การจัดเก็บ
วัตถุจัดเก็บ
ออบเจ็กต์ Storage ของ Web Storage API ให้การเข้าถึงที่จัดเก็บเซสชันหรือที่จัดเก็บในเครื่องสำหรับโดเมนเฉพาะ ซึ่งจะทำให้คุณสามารถอ่าน เพิ่ม แก้ไข และลบรายการข้อมูลที่เก็บไว้ได้
คุณสมบัติและวิธีการจัดเก็บอ็อบเจ็กต์
Property/Method | Description |
---|---|
key(n) | Returns the name of the nth key in the storage |
length | Returns the number of data items stored in the Storage object |
getItem(keyname) | Returns the value of the specified key name |
setItem(keyname, value) | Adds that key to the storage, or update that key's value if it already exists |
removeItem(keyname) | Removes that key from the storage |
clear() | Empty all key out of the storage |
เพจที่เกี่ยวข้องสำหรับ Web Storage API
Property | Description |
---|---|
window.localStorage | Allows to save key/value pairs in a web browser. Stores the data with no expiration date |
window.sessionStorage | Allows to save key/value pairs in a web browser. Stores the data for one session |
คุกกี้กับที่เก็บข้อมูลในเครื่อง
คุกกี้มีไว้สำหรับแอปพลิเคชันไคลเอนต์ - เซิร์ฟเวอร์ (เบราว์เซอร์ - เซิร์ฟเวอร์)
ที่เก็บข้อมูลในเครื่องมีไว้สำหรับแอปพลิเคชันไคลเอนต์ (เบราว์เซอร์)
คุกกี้เชื่อมโยงกับเว็บไซต์ หากข้อมูลมีไว้สำหรับการใช้งานไคลเอ็นต์ การส่งคุกกี้ในทุกส่วนหัวของ HTTP จะเป็นช่วงเอวของแบนด์วิดธ์
ผู้ใช้บางคนปิดใช้งานคุกกี้ตามกฎในเบราว์เซอร์
คุกกี้มีขนาดจำกัดที่ 4 กิโลไบต์ Local Storage มีขีดจำกัด 5 เมกะไบต์ต่อโดเมน
คุกกี้มีวันหมดอายุ ที่เก็บข้อมูลในเครื่องยังไม่มี
รองรับเบราว์เซอร์
Storage API
รองรับในทุกเบราว์เซอร์:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 8-11 | Yes | Yes | Yes | Yes |