JavaScript Browser APIs
Practise JavaScript Browser APIs with runnable examples for location, files, storage, drawing, and device features. Learn permissions, output, and common mistakes.
15 programs · open one, then the next
Start with Geolocation API- 01Geolocation APIIntermediateRead latitude and longitude in JavaScript with getCurrentPosition on HTTPS or localhost. A button starts the request; refusal and timeout errors are handled.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 02Notifications APIIntermediateRequest a desktop reminder in JavaScript with Notification.requestPermission and new Notification. Respect denial; system settings can still hide the message.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 03Clipboard APIIntermediateCopy and read text in JavaScript with navigator.clipboard.writeText and readText after button clicks. Use HTTPS; browser permission can block either operation.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 04Fullscreen APIBeginnerToggle a panel in JavaScript with requestFullscreen and exitFullscreen. Handle failed requests and fullscreenchange, including when Escape exits the display.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 05Page Visibility APIBeginnerReport tab visibility in JavaScript using document.hidden and visibilitychange. The page and console show state; a visible tab does not prove attention.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 06Web WorkersAdvancedAdd test marks in JavaScript with a Blob web worker and postMessage. Print the returned total, then terminate the worker; it cannot directly edit the page.Open example →jsconst workerSource = ` self.onmessage = event => { const total = event.data.reduce((sum, value) => sum + value, 0); self.postMessage(total);
- 07Service WorkersAdvancedCache a page in JavaScript with service-worker install and fetch handlers on HTTPS or localhost. Use three files and reload online before testing offline.Open example →js// Three files in the same folder. Serve them on HTTPS or localhost. // index.html: // <button id="setup">Enable offline page</button><p id="status"></p> // <script src="app.js"></script>
- 08IndexedDBAdvancedSave an attendance record in JavaScript with IndexedDB.put, then read it after the write transaction completes. This browser database is not a shared server.Open example →jsconst request = indexedDB.open('AttendancePractice', 1); request.onupgradeneeded = () => { const db = request.result; if (!db.objectStoreNames.contains('students')) db.createObjectStore('students', { keyPath: 'id' });
- 09File APIIntermediatePreview a selected text file in JavaScript with File.text and textContent, without uploading it. Check cancelled selection and file size before reading.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 10Canvas APIIntermediateDraw an attendance bar in JavaScript with a 2D canvas, fillRect, and fillText. Map 24 students to 240 pixels; canvas charts also need a readable text summary.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 11Web Audio APIAdvancedPlay a short tone in JavaScript with AudioContext, an oscillator, and a gain node. A click resumes audio; the quiet 440 Hz tone stops after 0.3 seconds.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 12Speech SynthesisBeginnerSpeak typed text in JavaScript with SpeechSynthesisUtterance and speechSynthesis.speak. Cancel old speech first; the requested voice depends on the device.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 13Vibration APIBeginnerRequest a buzz-pause-buzz pattern in JavaScript with navigator.vibrate after a click. Check support; an accepted request does not guarantee a felt vibration.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 14Battery APIIntermediateShow battery percentage and charging state in JavaScript with navigator.getBattery and change events. Use HTTPS; many browsers do not expose battery data.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>
- 15Intersection ObserverIntermediateWatch a card in JavaScript with IntersectionObserver at a 0.5 threshold. Stop observing once half is in view; geometric visibility does not prove reading.Open example →js<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>JavaScript practice</title>