I am trying to make a simple website with only HTML & JavaScript. I want to display the visitors IP address on the screen. I tried to search a lot and came to a conclusion that that is not possible through JavaScript and I would have to use some server side scripting language like PHP. However, I don't want to increase the overheads, how can I achieve this without server side programming?
It's easy, just find a service that will return the IP to you via JSONP:
How to get client IP address using jQuery
Other resources:
Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?
You can't. JavaScript has no access to any API that will give that information other than via an HTTP request.
NO. Javascript, can't access IP Address. You need an API or a PHP/ASP/JSON File on your web Server. Try this service
<script src="http://www.codehelper.io/api/ips/?js"></script>
<script>
alert(codehelper_ip.IP);
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.