如何使用javascript浏览器获取当前位置、鼠标位置和当前url

如何使用javascript浏览器获取当前位置、鼠标位置和当前url,javascript,Javascript,我正在创建一个监控网站的工具 为此,我需要使用javascript浏览器检测获取当前位置、鼠标位置和当前url 我该怎么做 我知道下面的代码对于获取当前位置是正确的 var loc = navigator.geolocation.getCurrentPosition; console.log(loc); 要访问对象的属性,请使用(句点)而不是,(逗号) getCurrentPosition是一个函数,您需要调用它(使用()) getCurrentPosition可能必须发出网络请求才能得出结果

我正在创建一个监控网站的工具

为此,我需要使用javascript浏览器检测获取当前位置、鼠标位置和当前url

我该怎么做

我知道下面的代码对于获取当前位置是正确的

var loc = navigator.geolocation.getCurrentPosition;
console.log(loc);
  • 要访问对象的属性,请使用
    (句点)而不是
    (逗号)
  • getCurrentPosition
    是一个函数,您需要调用它(使用
    ()
  • getCurrentPosition
    可能必须发出网络请求才能得出结果,因此它是异步的。必须将回调函数作为其第一个参数传递给它
  • 例如:

    function showPositionData(result) {
        console.log(result);
    }
    navigator.geolocation.getCurrentPosition(showPositionData);