3 Unique Javascript Window APIS ✨

abdelrahman

Abddelrahman Saad

Posted on November 11, 2020

3 Unique Javascript Window APIS ✨

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 🟢")
}
Enter fullscreen mode Exit fullscreen mode

2-navigator.language:

Lets you get the language of the browser


console.log(navigator.language)

 //output en-Us
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

That's it, Have a productive day ❤️

💖 💪 🙅 🚩
abdelrahman
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