get ip address using javascript code example
Example 1: how to get ip address in javascript
fetch('https://api.ipify.org/?format=json')
.then(response => response.json())
{
"ip": "user_ip"
}
Example 2: how to get user ip address in javascript
<script>
function getIP(json) {
alert("My public IP address is: " + json.ip);
}
</script>
<script src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"> </script>
Example 3: javascript ip address
$.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=<your_api_key>', function(data) {
console.log(JSON.stringify(data, null, 2));
});