Home / Learn HTML / HTML Geolocation and Other Browser APIs

HTML Geolocation and Other Browser APIs

HTML5 pages can ask for the visitor location, vibrate a phone, read the battery and more. The browser always asks permission first.

In shortThese features need permission and a secure (https) page. Some are blocked inside previews, so the result may show a message.

Definition

The Geolocation API finds the visitor's position with navigator.geolocation. The browser always asks permission first, and it works only on HTTPS. Other useful browser APIs include the clipboard, notifications, fullscreen and the share sheet.

Theory in plain words

Permission flowScript asksBrowser asks userUser allowsData returned
Permission flow

What it is

Browser APIs give pages extra powers: location, camera, clipboard, notifications and more, always with user permission.

Why we use it

They make web pages behave like apps.

How it works

JavaScript asks the browser. The browser asks the user. If allowed, data comes back to the script.

Where it is used

  • Maps and delivery apps
  • Photo upload with camera
  • Copy buttons
Get locationTry it Yourself
Online or offlineTry it Yourself
Screen sizeTry it Yourself
Language of the browserTry it Yourself
Vibrate (phones)Try it Yourself
Full screenTry it Yourself
Copy to clipboardTry it Yourself
Share sheetTry it Yourself
Text to speechTry it Yourself
Page visible or hiddenTry it Yourself
Date and timeTry it Yourself
TimersTry it Yourself

Quick quiz

1. Browsers ask this before giving location

2. Geolocation needs

3. navigator.onLine tells

My notes
Ask a question about this lesson