What are the frequently useful API in HTML5 ?
HTML Geolocation API
The Geolocation API is used to get the current location of the user or the page visitor. It will show the user’s location only if the user allows it to do so, as it compromises the security and privacy of the user.
Methods available in Geolocation API:
- getCurrentPosition() Method - The getCurrentPosition() method returns an object with properties such as latitude, longitude, accuracy, altitude etc.
- watchPosition() Method - This method will return the current position of the user as well as the updated location when the position of the user changes or the user travels from one location to another location.
- clearWatch() Method - This method will stop the watchPosition() method to not tracing the user anymore.
HTML Drag and Drop API
Drag and Drop is a common feature nowadays, where you can drag an item from one place and drop it in another. To use drag and drop first you have to add the draggable="true" attribute to the element.
HTML Web Storage API
HTML Web Storage API is used to store the data on the web browser. Early, the data was stored in the form of cookies that can store a small amount of data and can-not transferred further to the server. But, HTML5 introduces us to the Web Storage API that can store large data as compared to cookies and can be transferred to the server. Using this API for storing data is more secure than using cookies.
Web Storage API provides us with two objects to work with:
- window.sessionStorage - This object temporarily stores the data on the web browser such that if the browser is refreshed or closed the data stored will be lost.
- window.localStorage - localStorage permanently stores the data on the browser with no expiration such that will not be lost even if the browser is refreshed.
HTML Web Worker API
Generally, when the JavaScript is uploading for the page, the page got stuck until uploading gets finished. The Web worker API helps us to upload the JavaScript without affecting the performance of the page. It helps to run JavaScript run in the background independent of other scripts.