Search code examples
javascripthtmlgeolocation

browser Allow/Disallow buttons on geolocation request


Is it possible to attach event to browser geolocation request state?

When bar is visible show arrow to user... something like this:

enter image description here


Solution

  • BTW, You're going down a dark path of having to have a different help text for various versions of browsers/types/etc.

    For instance, Firefox 29.0.1 permission window:

    FireFox 29 Geo Permissions

    In any event, I would suggest a variation of Nerdicus recommendation:

    Instead of defaulting to show the arrow & then just hiding it when the JavaScript gets called, I would default display: none;, and then trigger a .show() right before you make the geolocation request to reduce your "flicker", and then hide it in your success/error callback.

    Additionally, in your success handler, you can create a cookie (probably at the session level)

    $.cookie("geoperm", "true")
    

    Then you can check for existing permissions before showing the tooltip:

    if (navigator.geolocation) {
      // Show the arrow here, but only if there isn't a cookie stating we have permissions
      if(!$.cookie("geoperm")) $("#geo-helper").show();
    
      navigator.geolocation.getCurrentPosition(success, error);
    } else {
      error('not supported');
    }