Home >Web Front-end >JS Tutorial >How Can I Get a Client's IP Address Using Only JavaScript?

How Can I Get a Client's IP Address Using Only JavaScript?

Susan Sarandon
Susan SarandonOriginal
2024-12-16 14:50:15778browse

How Can I Get a Client's IP Address Using Only JavaScript?

Obtaining Client IP Address Using JavaScript

Need to determine a client's IP address strictly through JavaScript, without involving server-side code or SSI? We can utilize a third-party web service that responds with JSON data.

The following JSON-based IP lookup services have proven reliable:

Abstract

let apiKey = '1be9a6884abd4c3ea143b59ca317c6b2';
$.getJSON('https://ipgeolocation.abstractapi.com/v1/?api_key=' + apiKey, function(data) {
  console.log(JSON.stringify(data, null, 2));
});

Include jQuery:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

The above is the detailed content of How Can I Get a Client's IP Address Using Only JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn