Skip to content

Instantly share code, notes, and snippets.

@m1m1s1ku
Created July 24, 2017 18:27
Show Gist options
  • Save m1m1s1ku/5a87a08ed1a3a5558e83926c9f45a960 to your computer and use it in GitHub Desktop.
Save m1m1s1ku/5a87a08ed1a3a5558e83926c9f45a960 to your computer and use it in GitHub Desktop.
/**
* Get current user IP (in callback)
* @param {string} callback
*/
function getIp(callback){
var url = 'https://api.ipify.org/';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(this.readyState === XMLHttpRequest.DONE)
if(this.status === 200)
callback.apply(this.responseText);
}
xhr.open('GET', url, true);
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment