3 Unique Javascript Window APIS ✨
Abddelrahman Saad
Posted on November 11, 2020
Javascript has a powerful built-in API that makes our life easier as developers.
Today we're going to cover 3 of them.
Note: These APIS are experimental so you need to check of the browser support them first before using it in production
1-navigator.Online:
Lets you check the user internet connection, return false if the connection is lost and true when it back
if( !navigator.online ) {
console.log(" You're offline, check your connection. 🔴")
} else {
console.log(" Your connection is back 🟢")
}
2-navigator.language:
Lets you get the language of the browser
console.log(navigator.language)
//output en-Us
3-navigator.geolocation:
Lets you get the location of the device
navigator.geolocation.getCurrentPosition(displayPosition)
function displayPosition(position){
console.log('Latitude:' + position.coords.latitude)
console.log('Longitude:' + position.coords.longitude)
}
//Latitude: 40.1294478
//Longitude: 41.34804699999998
That's it, Have a productive day ❤️
💖 💪 🙅 🚩
Abddelrahman Saad
Posted on November 11, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Alternative to AbortController for Handling Async Timeouts in JavaScript
November 27, 2024
javascript Can Node.js Really Handle Millions of Users? The Ultimate Guide to Massive Scale Applications
November 28, 2024