Which HTML5 API allows web applications to store data in the user's browser…
2023
Which HTML5 API allows web applications to store data in the user's browser and retrieve it later, even after closing the browser?
- A.
Web Storage API
- B.
WebSocket API
- C.
Geolocation API
- D.
IndexedDB API
Attempted by 78 students.
Show answer & explanation
Correct answer: A
The Web Storage API is an HTML5 feature that provides mechanisms by which browsers can securely store key-value pairs in a much more intuitive fashion than using cookies. It provides two mechanisms:
localStorage: Stores data with no expiration date. The data remains saved in the user's browser even after the browser or the tab is closed and reopened.sessionStorage: Stores data only for the duration of the page session (data is lost when the specific tab or browser is closed).
Since the question asks for an API that allows data to be retrieved later even after closing the browser, the Web Storage API (via localStorage) perfectly fits this definition.