4

如何防止 Firefox 在每次请求时都要求用户分享他们的位置?

我正在使用谷歌地图 API。下面是我分享位置的代码。在 Firefox 中,它总是要求与下面的弹出窗口共享位置。每次都会发生这种情况,无论我点击Share还是Not Now

在此处输入图像描述

下面是我的代码

<% if (!Page.IsPostBack)
{ %>
// opened the share location

if (navigator.geolocation) 
{
    try 
    {
        navigator.geolocation.getCurrentPosition(onPositionUpdate);
    } 
    catch (err) 
    {
        alert(err);
    }
}
else 
{
        alert("You location is not available. Please enter your location to continue!");
}
<%}%>

function onPositionUpdate(position) 
{
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    try 
    {
        var latLng = new google.maps.LatLng(lat, lng);

        if (marker == null) 
        {
            alert("Sorry we are not able to update your location.");
        }
        else 
        {
            setTimeout(function () 
                {
                    marker.setPosition(latLng);
                    map.setCenter(latLng);
                    document.getElementById('ctl00_ContentPlaceHolderBody_latSel').value = lat;
                    document.getElementById('ctl00_ContentPlaceHolderBody_lngSel').value = lng;
                    geocodePosition(latLng);
                }, 100);
        }
    }
    catch (err) 
    {
        alert(err);
    }
}
4

3 回答 3

1

很可能是因为当您在开发服务器上运行您的网站时,您的端口号会发生变化。转到项目属性 -> Web -> 服务器部分:并设置特定端口而不是自动分配。

于 2013-10-08T13:55:13.640 回答
1

因为 webkit 和 opera 浏览器的默认设置是正常的。对于 iOS,需要在 css 中使用带有 -webkit 关键字的 html5 某些功能在其他浏览器中不起作用。基本上 safari、chrome、opera 都用于移动设备,并且设备功能可以很好地与这些设备配合使用。Firefox 浏览器不是移动设备的更好选择。

于 2013-10-14T07:16:04.517 回答
1

发生这种情况是因为您正在使用navigator.geolocation.getCurrentPosition.

浏览器必须征求用户的许可才能共享您的地理位置。这取决于您的浏览器的设置。如果您想始终在 Firefox 中共享您的地理位置,只需点击此链接并转到最后一段。

位置感知浏览在 Firefox 中始终是可选的。未经您的许可,绝不会发送任何位置信息。如果您希望完全禁用该功能,请按照以下步骤操作:

  • 在 URL 栏中,键入 about:config
  • 输入 geo.enabled
  • 双击 geo.enabled 首选项
  • 位置感知浏览现在已禁用
于 2013-10-14T07:19:34.877 回答