I am using HTML5 Geolocation to get the user's latitude and longitude. It works fine on all browsers when the page is opened directly, but now I have to put the geolocation code inside an iframe. After putting it in the iframe, the geolocation doesn't prompt for the user's coordinates.
How do I get the user's latitude and longitude when the page is loading in an iframe?
let's say this is the code:
<!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>