Linked Questions

Popular Questions

Public IP address as variable in JavaScript/HTML

Asked by At

How can I get a public IP address as a; var ip = $("#ip") ?

I hope to achieve is to put a public IP address into a var.

So far I have this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
var yourip = document.getElementsByTagName("body")[0].ip
window.alert("your IP is" + yourip);
</script>
<body>
<span id="ip"></span>
</body>
<script type="text/javascript">
$.getJSON("http://jsonip.com?callback=?", function (response) {
$("#ip").text(response.ip);
});
</script>

Related Questions