Skip to content

Small Javascript library for obtaining the IP address and/or location using CloudFlare and ipinfo.io (not affiliated).

Notifications You must be signed in to change notification settings

NelsWebDev/JS-ClientLocation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

JS-ClientLocation

Small Javascript library for obtaining the IP address and/or location using CloudFlare and ipinfo.io (not affiliated).

Note: Ideally you should use the JavaScript location API to obtain the user's location. This simply is an alternative which does not require the visitor to enable location services.

Usage

Download the client-location.js file, embedding it into your web page using HTML script tags.

<script src="//domain.com/path/to/js/client-location.js"></script>

Feel free to rename the userIPAddress and jsonLocationObj to whatever you want.

userLocation = new ClientLocation();
  userLocation.getUserIp( function (userIPAddress){
    // callback code here
  });  
  userLocation.getUserLocation( function (jsonLocationObj) {
    // callback code here
  });

About

Small Javascript library for obtaining the IP address and/or location using CloudFlare and ipinfo.io (not affiliated).

Resources

Stars

Watchers

Forks