JavaScript provides various Browser API Reference to interact with the browser environment, the document, and events. Here is a list of key objects and properties along with a brief explanation of each:
- The global object representing the browser window or tab.
- Examples:
- window.innerWidth
- window.innerHeight
- window.alert()
- window.location
- Represents the HTML document loaded in the window.
- Examples:
- document.getElementById()
- document.getElementById()
- document.querySelector()
- document.querySelectorAll()
- document.title
- document.URL
- Provides information about the browser.
- Examples:
- navigator.userAgent
- navigator.language
- navigator.onLine
- navigator.geolocation
- Provides information about the user's screen.
- Examples:
- screen.width
- screen.height
- screen.colorDepth
- screen.orientation
- Provides information about the current URL.
- Examples:
- location.href
- location.hostname
- location.pathname
- location.searc
- Allows manipulation of the browser session history.
- Examples:
- history.back()
- history.forward()
- history.go()
- history.length
- Provides access to the browser's debugging console.
- Examples:
- console.log()
- console.error()
- console.warn()
- console.table()
- The base event object from which all other event objects derive.
- Examples:
- event.type
- event.target
- event.preventDefault()
- event.stopPropagation()
- Represents events that occur due to the user interacting with a pointing device.
- Examples:
- event.clientX
- event.clientY
- event.button
- event.relatedTarget
- Represents events that occur due to the user interacting with a keyboard.
- Examples:
- event.key
- event.code
- event.altKey
- event.ctrlKey
- Represents events that occur due to the user interacting with a touch screen.
- Examples:
- event.touches
- event.targetTouches
- event.changedTouches
- Represents events that occur when an element gains or loses focus.
- Examples:
- event.relatedTarget
- Represents events that occur when the value of an
<input>
,<textarea>
, or<select>
element changes. - Examples:
- event.inputType
- event.data
- Allows for making HTTP requests to retrieve data from a URL without refreshing the page.
- Examples:
- xhr.open()
- xhr.send()
- xhr.responseText
- xhr.status
- A modern interface for making HTTP requests.
- Examples:
fetch(url).then(response => response.json())
- Allows storage of key-value pairs in a web browser with no expiration time.
- Examples:
- localStorage.setItem()
- localStorage.getItem()
- localStorage.removeItem()
- Allows storage of key-value pairs for the duration of the page session.
- Examples:
- sessionStorage.setItem()
- sessionStorage.getItem()
- sessionStorage.removeItem()
- Represents form data that can be sent using XMLHttpRequest or fetch.
- Examples:
- formData.append()
- formData.delete()
- formData.entries()
- Provides utilities for working with URLs.
- Examples:
- new URL()
- url.searchParams
- url.href
- url.pathname
- Represents a background task that can be run without interfering with the user interface.
- Examples:
- new Worker()
- worker.postMessage()
- worker.terminate()
- Provides a way to open a persistent connection between the client and server.
- Examples:
- new WebSocket()
- webSocket.send()
- webSocket.onmessage
- Calls a function or executes code after a specified delay.
- Examples:
const timeoutID = setTimeout(() => { console.log('Hello!'); }, 1000);
clearTimeout(timeoutID);
- Repeatedly calls a function or executes code at specified intervals.
- Examples:
const intervalID = setInterval(() => { console.log('Hello again!'); }, 1000);
clearInterval(intervalID);
- Tells the browser to execute a callback function to update an animation before the next repaint.
- Examples:
- requestAnimationFrame(callback);
- Provides access to the device’s geographic location.
- Examples:
- navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
- Provides information about the physical orientation of the device.
- Examples:
- window.addEventListener('deviceorientation', handler);
- Provides information about the acceleration of the device.
- Examples:
- window.addEventListener('devicemotion', handler);
- Represents media elements, like
<audio>
and<video>
. - Examples:
- video.play()
- video.pause()
- audio.volume
- Provides access to connected media input devices like cameras and microphones.
- Examples:
navigator.mediaDevices.getUserMedia(constraints).then(stream => { /* use stream */ });
- Provides a context for drawing on a
<canvas>
element. - Examples:
- canvas.getContext('2d')
- ctx.fillRect()
- ctx.drawImage()
- Provides a context for drawing 3D graphics on a
<canvas>
element using WebGL. - Examples:
- canvas.getContext('webgl')
- gl.createShader()
- gl.createProgram()
- Provides access to the clipboard for reading and writing text.
- Examples:
navigator.clipboard.writeText('Text to copy');
navigator.clipboard.readText().then(text => { /* use text */ });.
- Provides a way to display system notifications to the user.
- Examples:
new Notification('Hello!');
Notification.requestPermission().then(permission => { /* use permission */ });
- Represents the data being dragged during a drag-and-drop operation.
- Examples:
event.dataTransfer.setData('text/plain', 'Hello, world!');
event.dataTransfer.getData('text/plain');
- Provides a low-level API for storing large amounts of structured data.
- Examples:
- indexedDB.open('myDatabase', 1);
- Provides a way to intercept and handle network requests, including programmatically managing a cache of responses.
- Examples:
navigator.serviceWorker.register('/service-worker.js');
- Provides access to performance-related information.
- Examples:
- performance.now()
- performance.mark()
- performance.measure()
- Provides a way to receive messages pushed from a server.
- Examples:
registration.pushManager.subscribe(options);
- Provides the ability to watch for changes being made to the DOM tree.
- Examples:
new MutationObserver(callback).observe(targetNode, config);
- Provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or the top-level document's viewport.
- Examples:
new IntersectionObserver(callback).observe(targetElement);
- Provides a way to observe changes to the size of an element's content or border box.
- Examples:
new ResizeObserver(callback).observe(targetElement);