javascript - 通过与 https://localhost:3000 的混合内容的安全连接阻止了对地理位置的访问
问题描述
我已经实现了devise omniauth
设置,当我使用 Facebook、twitter 或 google 登录时,html5 geolocation
返回一个position unavailable error
. 但是当我以常规方式登录时,devise user
它工作得很好!html5 geolocation
使用社交媒体帐户登录时,如何允许访问我的 Rails 应用程序?
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setGeoCookie,showError);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
window.location = window.location;
window.alert("Permission denied");
break;
case error.POSITION_UNAVAILABLE:
window.location = window.location;
window.alert("Location information is unavailable.");
break;
case error.TIMEOUT:
window.location = window.location;
window.alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
window.location = window.location;
window.alert("An unknown error occurred.");
break;
}
location.reload();
}
更新 1
我将代码更改为以下内容,并且在浏览器控制台中出现以下错误:
Origin does not have permission to use Geolocation service
[blocked] Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000.
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error, options);
} else {
alert("Geolocation is not supported by this browser.");
}
}
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
关于如何解除阻止的任何想法?
解决方案
这不是 Rails 问题,而是 Javascript 问题。在您的模板、CSS 或 Javascript 中的某处,您从 http 而不是 https 加载某些内容。使用浏览器的检查器找出罪魁祸首。
推荐阅读
- mysql - 管理存储在 MySQL 表中的路径字符串
- python - 如何在 x 标签中添加实际价格?
- laravel - Laravel 关系:试图获取非对象的属性“名称”
- python - 如何根据日期列表溢出熊猫系列
- download - 我在哪里可以下载 TradingView 的技术图表库?
- amazon-web-services - Aws-vault:无法获取凭据 - InvalidClientTokenId:请求中包含的安全令牌无效
- javascript - 打破包含异步操作的无限循环
- oracle - Oracle 到 Postgres 的转换将游标作为参数传递
- javascript - 反应状态下的许多布尔属性 - 如何重构?
- python - 尝试根据条件在电子邮件中附加 pdf 时,Django 文件不存在错误