2011-08-20 51 views
0

簡單的問題..如果用戶選擇不允許geolocator彈出,我該如何設置重定向?如果允許和錯誤我已經涵蓋。工作正常。但我不知道如何設置不允許選擇。jquery mobile geolocation

function showLocation(position) { 
     var latitude = position.coords.latitude; 
     var longitude = position.coords.longitude; 
     //window.location = "/restaurant/latitude/40.714269/longitude/-74.005972/"; 
     window.location = "/restaurant/"; 
    } 

    function errorHandler(err) { 
     if(err.code == 1) { 
      alert("Error: Can not access!"); 
     }else if(err.code == 2) { 
      alert("Error: Position is unavailable!"); 
     } 
    } 
    function getLocation(){ 

     if(navigator.geolocation){ 
      // timeout at 60000 milliseconds (60 seconds) 
      var options = {timeout:60000}; 
      navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options); 
     }else{ 
      alert("Sorry, browser does not support geolocation!"); 
     } 
    } 

回答

1

按照W3C Geolocation API spec,錯誤處理程序應與失敗的合適的理由被調用。這包括用戶拒絕的權限。

不幸的是,它似乎有一個bug/feature in Firefox如果您從彈出框中選擇Not Now,則什麼都不會發生 - 錯誤處理程序不會被調用。但是,如果您選擇Never Share,您的錯誤處理程序確實會被調用,並且您發佈的代碼會顯示爲Error: Can not access!

在Chrome中沒有第三個選項(只有AllowDeny),而且事情似乎在那裏工作得很好。

另見How to detect negative user response for geolocation其中提出了一個解決方案(涉及使用超時檢測出什麼都沒有發生和治療它一樣的權限被拒絕)

0

我看到你已經嘗試設置window.location。爲什麼這不適合你?

了window.location =「../nonGeoLocationPage.html」

+0

這工作。我不知道沒有訪問/錯誤1實際上是不允許選擇.. – user154107