私はjs経由でユーザーの場所にアクセスしようとしています。コードは正常に動作しているようですが、クロムには問題ありません。それをコーディングするとき、クロムは私の場所にアクセスしようとしていることを私に通知しますが、私はファイルからそれを実行していたので、私はそれを許可しませんでした。つまり、私はそれを許してくれました。それはうまく機能しました。Google chromeは私の場所を尋ねません - html/js
私はすぐに無料のホスティングサイトにアップロードしてクロムでテストしましたが、現在は機能が動作しなくても自分の位置が欲しいと思っています。私はそれを実行すると、それは完全に正常に動作します。
コード:
Date.prototype.Today = function() {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
}
Date.prototype.Time = function() {
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
}
var DateTime = new Date().Today() + " " + new Date().Time();
var Latitude = "Unavailable";
var Longitude = "Unavailable";
IP = GetIP("https://api.ipify.org/");
initGeolocation();
function GetIP(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
function initGeolocation()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(success);
}
}
function success(position)
{
Latitude = position.coords.latitude;
Longitude = position.coords.longitude;
document.write(DateTime + " " + IP + " " + Latitude + " " + Longitude);
}
document.write(DateTime + " " + IP + " " + Latitude + " " + Longitude);
私はそれをやった、他のサイトはそれにアクセスすることができます、クロムのちょうどこれは、それはtrynaがそれにアクセスする –