简体   繁体   中英

How to get the current location,mouse position and current url using javascript browser detect

I'm creating a tool to monitor a website.

For that I need to get the current location, mouse position, and current url using javascript browser detection

How can I do this?

I know that the code below is correct for getting the current position.

var loc = navigator.geolocation.getCurrentPosition;
console.log(loc);
  1. To access a property of an object use a . (period) not a , (comma)
  2. getCurrentPosition is a function , you need to call it (with () )
  3. getCurrentPosition may have to make network requests in order to figure out the result, so it is asynchronous. You have to pass it a callback function as its first argument.

Such:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM