HTML and CSS Reference
In-Depth Information
// reload the page
window.location.href = “";
window.onload = init;
Open the HTML page in a web browser, and you will be able to turn on editing (which
adds the contenteditable attribute), save the edits, and see those edits stick be-
cause they will be stored in the local storage ( Figure A-3 ).
Figure A-3. A simple application using local storage
Other storage options
Local storage is easy to use, but with that ease comes limits on its capabilities. It's really
not comparable to a database you would find on the back-end web server, which likely
describes the relationship between the stored data and provides methods for ensuring
data integrity. Since web technologies are moving toward enabling the creation of web
applications, having a fully capable database on the client end is a desirable option. One
such option is Web SQL, which essentially embeds an SQLite 3 database into the web
browser. This means Structured Query Language (SQL) commands can be used dir-
ectly from JavaScript. Pretty cool! Unfortunately, the future of Web SQL has darkened
considerably, because disagreements over standardizing the use of SQLite as the embed-
ded database has led to support being dropped for the initiative by the W3C. Because of
this, Mozilla has said it will drop support in Firefox, which means support is spotty and
not reliable going forward. Too bad.
Another option, which is currently supported only in Firefox but has planned support
from other major web browsers, is the Indexed Database API, 4 also known as In-
dexedDB. This database solution stores key/value pairs, like web storage, but includes
more sophisticated features, such as transactions for ensuring data is successfully com-
mitted to the database, which helps guarantee data integrity. IndexedDB is not as soph-
isticated as Web SQL (it's not a relational database), but it is more capable than web
storage and is looking like it will be the option to use in the future for handling client-
side data storage that is more complex than what web storage will accommodate.
Search WWH ::

Custom Search