Window Object:
Web APIs:
Let's see what all interesting things are possible using different WebAPIs and Window methods
You can grab user's current location,
using:
window.navigator.geolocation.getCurrentPosition
If the user is moving, you can code it to send regular location updates at a fixed time interval,
You can store all the location updates, in localStorage as well
You can grab user's file input and show a preview on UI using FileReader:
const reader = new FileReader();
You can grab user's audio input and convert it to text using:
window.SpeechRecognition()
You can store it to localStorage as well
You can record user's audio input and play it back using:
window.SpeechRecognition(), and localStorage
You can store it to localStorage as well
You can grab user's camera input for image using:
navigator
.mediaDevices
.getUserMedia({
video: true
})
You can store it to localStorage as well
You can grab user's camera input for image, show image on UI using <img>
tag
navigator
.mediaDevices
.getUserMedia({
video: true
})
You can store it to localStorage as well
You can grab user's camera input video and audio using:
navigator
.mediaDevices
.getUserMedia({
video: true,
audio: true
})
You can store both audio and video to localStorage as well
You can record user's screen using:
const stream = await navigator.mediaDevices.getDisplayMedia({
video: true
});
You can store the recorded video to localStorage as well
You can record user's screen along with audio using:
const displayStream = await navigator
.mediaDevices
.getDisplayMedia({ video: true });
audioStream = await navigator
.mediaDevices
.getUserMedia({ audio: true });
You can store the recorded video and audio to localStorage as well
navigator.getBattery();
navigator.language
navigator.platform
navigator.userAgent
navigator.connection.effectiveType
navigator.onLine
// Scroll to the top of the page
window.scrollTo(0, 0);
// Open a new window with specific dimensions
window.open("https://example.com", "_blank", "width=500,height=500");
// Close the current window
window.close();
// Go back one page
window.history.back();
// Reload the page
window.location.reload();
// Print the current URL
window.location.href;
// Print the current URL
console.log(document.location.href);
console.log(document.URL);
// document.referrer: Returns the URL of the
// document that referred the current document.
console.log(document.referrer);
// Get the current title
console.log(document.title);
// Set a new title
document.title = "New Title";
// Print the document's root element
// usually the <html> element
console.log(document.documentElement);
// Print the <head> element
console.log(document.head);
// Print the <body> element
console.log(document.body);