Created
July 24, 2017 18:27
-
-
Save m1m1s1ku/5a87a08ed1a3a5558e83926c9f45a960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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