The browser support the Navigator object. We can get location of browser by the Geolocation property in Navigator object.
The Geolocation property supported in browser:
IE: IE9 versions or than.
Chrome: 5.0 versions or than.
Firefox: 3.5 versions or than.
Safari: 5.0 versions or than.
Opera: 16.0 versions or than.
Below demo will returns a Geolocation object that can be used to locate the you position:
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { alert('Latitude: ' + position.coords.latitude + '- Longitude: ' +position.coords.longitude); }, function () { alert("Browser doesn't support Geolocation"); }); } else { // Browser doesn't support Geolocation alert("Browser doesn't support Geolocation"); }
Here is demo width my browser and this site.
Thanks for watching!