ユーザーの緯度と経度を取得するために HTML5 Geolocation を使用しています。ページを直接開いた場合はすべてのブラウザーで正常に動作しますが、位置情報コードを iframe 内に配置する必要があります。iframe に配置した後、ジオロケーションはユーザーの座標を要求しません。
ページが iframe に読み込まれているときに、ユーザーの緯度と経度を取得するにはどうすればよいですか?
これがコードだとしましょう:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;    
  }
</script>
</body>
</html>