Our Code has a Geolocation request to the browser and IE shows the confirmation popup for user to select the option. If the user has clicked on the cross [X] button on the window nothing happens. Is there a way to capture the event??
-
Have you had a look at this? Might be helpful. https://stackoverflow.com/questions/6092400/is-there-a-way-to-check-if-geolocation-has-been-declined-with-javascript – Oliver Trampleasure Dec 23 '18 at 17:32
3 Answers
The script below launches on page load and asks the user to use their location. I've simply added a small bit of code from the documentation example to check the error code - Error Code 1 is for permission denied..
There are multiple reasons why permission may be denied, for instance in the code snippets here an error code of 1 was returned, but due to Stack Overflow denying the geolocation functionality by policy, similarly on JSFiddle.
You could instead use the error message, which appears more precise. Different browsers have slightly different error messages:
- "User denied Geolocation" (Safari and Chrome)
- "User denied geolocation prompt" (Firefox).
You could instead use the following check on the error message, rather than the code:
if ( err.message == "User denied Geolocation" || err.message == "User denied geolocation prompt" ) {
// Your code goes here
}
Example Javascript
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
// Check for permission denied error
if (err.code == 1) {
alert("Permission denied to use location");
// Add your code here
}
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);

- 3,293
- 1
- 10
- 25
-
Thanks Oliver for the Brief... But IE when clicked on the specific region shown (X button) it is not throwing any response. Is there something that can be done on that. – user1715850 Dec 24 '18 at 05:17
-
Tried your solution and IE is not throwing Error Message on click of the X button on the right top Corner – user1715850 Dec 24 '18 at 05:28
actually Oliver means that before you click X button, you have been able to get the error message. the err get error message after navigator.geolocation.getCurrentPosition failed to get the location info. you can find the alter window has appear before click X button, and you can add code their if you failed to get the location.

- 274
- 1
- 5
-
Thanks but, really I am unable to get the point that you are discussing. I have tried the code and on lick of the close button IE is not throwing any error or console. Is there something am I doing wrongly. Please guide with an example. Happy New year – user1715850 Jan 02 '19 at 16:55
-
The event of the X button is the code logical of IE, javascript can't capture the event. may i know why you have to capture the event? maybe we can help try to find some other workaround? – DevPreSupport_MSFT Jan 03 '19 at 02:21
-
actually our site checks for nearby branches and the details are populated as its branch specific, when the user is not ready to share the location we must update with a default branch, which is not feasible with this issue. Thanks Good day – user1715850 Jan 14 '19 at 09:49
we get this double confirmed that IE don't support capturing this event, sorry for the inconvenience maybe caused by this. meanwhile, not sure if the below workaround can help you. use "a = navigator.geolocation.getCurrentPosition(success);" instead of "navigator.geolocation.getCurrentPosition(success, error, options);" and then manuall check if a is a null value, if it is null which means customer hasn't been ready to share the location. is this ok for you?
thanks

- 274
- 1
- 5