1
votes

How can I automatically enable browser location using jQuery? Currently I can detect whether location is enabled or not from the code written below:

setInterval(function () {
    navigator.geolocation.getCurrentPosition(positionFound, positionNotFound);
}, 6000);

function positionFound() {
    return true;
}

function positionNotFound() {
     var template = site_url + 'front/auth/setLocationFancybox';
    if (!$('.fancybox-overlay').html()) {
        $.fancybox.open({
            padding: 0, 
            href: template, 
            type: 'iframe', 
            'closeBtn': false
        });
    }
}

In the fancybox there will be two buttons:

  1. Turn on location: By which browser location will be turned on.
  2. Cancel: By which current parent window will get closed from the fancybox.

How can I turn on browser location and how can I close parent window from fancybox?

1
You can't automatically enable it. It's down to the user's preferences which is out of control of JS. - Rory McCrossan
There's a reason why the browser asks for permission, you know. - JJJ
Thanks Rory McCrossan & Juhana. But can we close the current tab from fancybox. If yes how?? I am using Php- Codeigniter, jQuery, AngularJS. - Abhranil Majumder

1 Answers

1
votes

It is not possible to turn on browser location using JavaScript/jQuery. Users need to grant permissions in their preferences. Your best option there is to specifically ask your users to enable it.

To close the parent window from fancybox you can use the following line of code:

parent.$.fn.fancybox.close();