使用 (navigator.geoloction) 的浏览器功能检测错误
browser feature detection error using (navigator.geoloction)
我写了一个脚本来检查我的浏览器是否有功能。以下脚本产生错误:
<!DOCTYPE HTML>
<html>
<head>
<title id="title"> code Issues </title>
</head>
<body>
//=================== testing the feature detection method by using geolocation =======================//
function geosuccess(position)
{
var cords = position.cords;
var latitude = position.latitude;
var longitude = postion.longitude;
var message = "You're at " + latitude + ", " + longitude
alert(message);
}
function geoError(errorObj)
{
alert(errorObj.message);
}
if(typeof navigator.geolocation != "undefined")
{
console.log("inside geolocation");
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
}
else
{
alert("thos page uses Geolocation and your browser doesn't support it");
}
//=================== End of testing the feature detection method by using geolocation =======================//
</script>
<h1>List Publishers Ltd.</h1>
<div class="book">
<h2>Sprout.</h2>
<p>A book by J. Daniel Bedford</p>
<a href="#">Read now.</a>
</div>
</body>
</html>
如果我 运行 这个我得到一个错误 geosuccess
是 undefined
.
我尝试调试脚本,发现它无法检测函数 geoSuccess(position)
。
我希望我没有遗漏面向对象的概念,错误可能与浏览器有关。
首先,您的代码缺少起始 <script>
标记,但我认为这只是一个错误。
其次,您的代码将函数定义为 geosuccess
,但您将 geoSuccess
传递给了 getCurrentPosition
。请检查您的代码中的大小写是否匹配。
我写了一个脚本来检查我的浏览器是否有功能。以下脚本产生错误:
<!DOCTYPE HTML>
<html>
<head>
<title id="title"> code Issues </title>
</head>
<body>
//=================== testing the feature detection method by using geolocation =======================//
function geosuccess(position)
{
var cords = position.cords;
var latitude = position.latitude;
var longitude = postion.longitude;
var message = "You're at " + latitude + ", " + longitude
alert(message);
}
function geoError(errorObj)
{
alert(errorObj.message);
}
if(typeof navigator.geolocation != "undefined")
{
console.log("inside geolocation");
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
}
else
{
alert("thos page uses Geolocation and your browser doesn't support it");
}
//=================== End of testing the feature detection method by using geolocation =======================//
</script>
<h1>List Publishers Ltd.</h1>
<div class="book">
<h2>Sprout.</h2>
<p>A book by J. Daniel Bedford</p>
<a href="#">Read now.</a>
</div>
</body>
</html>
如果我 运行 这个我得到一个错误 geosuccess
是 undefined
.
我尝试调试脚本,发现它无法检测函数 geoSuccess(position)
。
我希望我没有遗漏面向对象的概念,错误可能与浏览器有关。
首先,您的代码缺少起始 <script>
标记,但我认为这只是一个错误。
其次,您的代码将函数定义为 geosuccess
,但您将 geoSuccess
传递给了 getCurrentPosition
。请检查您的代码中的大小写是否匹配。