
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
I need a client side browser database in HTML5. What are my options?
The task we are going to perform in this article is about I need a client side browser database in HTML5 what are my options. Before diving into the article let’s have a look.
HTML5 introduces two mechanisms, similar to HTTP session cookies, for storing structured data on the client side. The two storages are session storage and local storage and they would be used to handle different situations.
You can use local storage in HTML5 for this purpose. The Local Storage is designed for storage that spans multiple windows and lasts beyond the current session.
Local Storage
The Web storage application programming interface includes a part for HTML5 local storage. It's a technique used by Web pages to locally store named key/value pairs in a user's web browser. Data stored and retrieved in HTML pages from the same domain is often done using local storage.
The local storage uses the localStorage object to permanently store data for your entire website.
localStorage.setItem(key, value) stores the data associated with a key.
localStorage.getItem(key) retrieves the data associated with the key.
For getting better understanding on how local storage was helpful let’s consider the following examples.
Example 1: Using HTML localstorage
In the following example we are using localstroge to store our data in the web without expiration.
<!DOCTYPE html> <html> <body> <input id="name" type="name" placeholder="enter your name" /> <button type="submit" onClick="handleClick()">Click</button> <br /> <div id="Varma"></div> <script> function handleClick() { if (typeof Storage !== "undefined") { let name = document.getElementById("name").value; localStorage.setItem("name", name); document.getElementById("Varma").innerHTML = "Welcome To Tutorialspoint" + " " + localStorage.name; } else { alert("Sorry! your browser doesn't support Web Storage"); } } </script> </body> </html>
On executing the above script, it will generate the output displaying the input field along with a click button. When a user clicks the button after entering the input field, the data gets stored in local storage where there is no validation.
Example 2
Considering the following example we are using localstroge to store our data in the web without expiration.
<!DOCTYPE HTML> <!DOCTYPE HTML> <html> <body> <script> if( localStorage.hits ){ localStorage.hits = Number(localStorage.hits) +1; } else{ localStorage.hits = 1; } document.write("Total Hits :" + localStorage.hits ); </script> <p>Refresh the page to increase number of hits.</p> <p>Close the window and open it again and check the result.</p> </body> </html>
When the script gets executed, it will generate an output consisting of total hits with a prompt. When the user refreshes the webpage, the hit count gets increased and stores the value.
- Related Articles
- Using client side XSLT transformations in HTML5
- How to display HTML5 client-side validation error bubbles?
- Does HTML5 allow you to interact with local client files from within a browser?
- MySQL Client Options
- Does HTML5 allow you to interact with local client files from within a web browser?
- What is client-side rendering in React?
- How can I turn on error information in my Web Browser?
- How can I replace & with an ampersand in my MySQL database?
- How can I write a form that assists my browser's auto-complete feature?
- What environment variables do I need to set up before I start running Java programs on my machine?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- MySQL Client Server-Side Help
- Client Checking file size using HTML5
- HTML5 applicationCache vs Browser Cache
- Are there any style options for the HTML5 Date picker?
