【发布时间】:2015-04-19 21:25:07
【问题描述】:
以下脚本在 FireFox 和 Chrome 中运行良好,但在 Internet Explorer 11 中,它总是失败(使用 POSITION_UNAVAILABLE)。
我已将浏览器设置为允许位置请求,并且我同意浏览器在请求权限时向我显示的提示。
我几乎可以肯定几个月前我最后一次尝试它时它运行良好。就 IE 的设置而言,我可能缺少什么?
<script type="text/javascript">
$(document).ready(function () {
if (Modernizr.geolocation)
{
navigator.geolocation.getCurrentPosition(positionSuccess, positionError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 10000 })
}
else
{
$("#GeoError").html("Unable to retrieve current position.")
}
});
function positionSuccess(position)
{
$("#Latitude").val(position.coords.latitude);
$("#Longitude").val(position.coords.longitude);
}
function positionError(error)
{
var message = "";
// Check for known errors
switch (error.code) {
case error.PERMISSION_DENIED:
message = "This website does not have your permission to use the Geolocation API";
break;
case error.POSITION_UNAVAILABLE:
message = "Your current position could not be determined.";
break;
case error.PERMISSION_DENIED_TIMEOUT:
message = "Your current position could not be determined within the specified timeout period.";
break;
}
// If it's an unknown error, build a message that includes
// information that helps identify the situation, so that
// the error handler can be updated.
if (message == "") {
var strErrorCode = error.code.toString();
message = "Your position could not be determined due to " +
"an unknown error (Code: " + strErrorCode + ").";
}
$("#GeoError").html(message)
}
</script>
另外,当我尝试http://html5demos.com/geo 时,我在 IE11 中遇到了同样的故障,其中 FireFox 和 Chrome 都可以正常工作。
【问题讨论】:
-
能否请您出示您的脚本参考资料?
-
不确定“脚本引用”是什么意思。我确实在页面顶部引用了modernizr-2.8.3.js 的本地副本,以及在上面显示的脚本之前的jquery-2.1.3.js、bootstrap.js 和respond.js 的本地副本。我遇到的问题不仅限于我的代码。
-
你有没有想过这个问题?我有同样的问题,我找不到解决办法
-
我的 IE11 也有同样的问题 - 有谁知道解决方案
-
如果你有这个问题,并且这个问题没有找到答案,请投票。
标签: html internet-explorer geolocation internet-explorer-11