Answers for "javascript ip adress"

5

how to get user ip address in javascript

// You can't extract the the public ip from with in the browser
// but you CAN use a third party, there are a lot of them out there
// I use www.ipify.org/

// because, according to them:
//
// 1. You can use it without limit (even if you're doing millions of 
//    requests per minute). 
// 2. ipify is completely open source (check out the GitHub repository).

//Here's a WORKING JS EXAMPLE:

<script>
function getIP(json) {
  alert("My public IP address is: " + json.ip);
}
</script>
<script src="https://api.ipify.org?format=jsonp&callback=getIP"></script>

// as seperate script tag
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"> </script>
Posted by: Guest on June-18-2020
0

javascript ip address

$.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=<your_api_key>', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
Posted by: Guest on March-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language