For now all we're going to do is check if the user has access to that geolocation API. If they don't we want to go ahead and print a message.
We're going to create an if statement. The geolocation API exists on navigator.geolocation, and we want to run some code if it doesn't exist:
var locationButton = jQuery('#send-location');
locationButton.on('click', function () {
if(navigator.geolocation){
}
});
So we're going to flip it. If there is no geolocation object on navigator we want to do something. We're going to use return to prevent the rest of the function from executing, and we're going to call the alert function available in all browsers that pops up one of those default alert boxes that makes you click on OK:
if(navigator.geolocation){
return.alert()
}
We're going to use this as opposed to a fancier modal. If you are using something like Bootstrap or Foundation, you can implement one of their built-in tools.
For now, though, we're going to use alert, which takes just one argument (a string, your message) Geolocation not supported by your browser:
var locationButton = jQuery('#send-location');
locationButton.on('click', function ()
if (!navigator.geolocation) {
return alert('Geolocation not supported by your browser.');
}
Now users who don't have support for this are going to see a little message, as opposed to wondering whether or not anything actually happened.