如果用户拒绝在 Firefox 中共享地理位置,则永远不会调用函数失败 [英] function fail never called if user declines to share geolocation in firefox
问题描述
所以我有这个 javascript 代码.在 safari 和 chrome 中,如果用户拒绝共享位置,它应该会失败;然而,在 Firefox 中,它没有.
So I have this javascript code. In safari and chrome, if user declines to share location, it goes to fail function as it should; however, in Firefox, it does not.
任何帮助表示赞赏.
function initGeolocation()
{
if( navigator.geolocation )
{
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( success, fail );
}
else
{
alert("Sorry, your browser does not support geolocation services.");
}
}
var map;
function success(position)
{
var longIDText = document.getElementById('longID');
var latIDText = document.getElementById('latID');
longIDText.value = position.coords.longitude;
latIDText.value = position.coords.latitude;
document.getElementById('coordSubmitID').click();
}
function fail(error)
{
alert("FAAAAAAAAAAIIIIIIIIIL")
var zip_code ;
while (true){
// Could not obtain location
zip_code = prompt("Please enter your current address or zip code","");
if ( zip_code == "" ) {
alert(zip_code +" is not a valid address. Please try again.");
}
else{
break;
}
}
var zipIDText = document.getElementById('zipID');
zipIDText.value = zip_code;
document.getElementById('coordSubmitID').click();
}
推荐答案
对于 Firefox it 似乎 PERMISSION_DENIED
仅在选择从不共享"时引发;如果对话框被关闭或选择不是现在",实际上什么也不会发生 - 即使在 mozillas geolocation demo 如果您关闭权限 UI,则什么也不会发生.
For Firefox it seems that PERMISSION_DENIED
is raised only if "Never share" is selected; if the dialog is dismissed or "Not now" is selected, effectively nothing happens - even on mozillas geolocation demo if you dismiss the permissions UI nothing happens.
这意味着 getCurrentPosition
可以返回,因为用户关闭了确认 UI,或者因为它成功启动了异步请求 - 似乎没有办法区分两者.
This means that getCurrentPosition
can return either because the user closed the confirmation UI, or because it successfully started it asynchronous request - there doesn't appear to be a way to discriminate between the two.
https://bugzilla.mozilla.org/show_bug.cgi?id=675533
这篇关于如果用户拒绝在 Firefox 中共享地理位置,则永远不会调用函数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!