0

Still pretty new to Javascript, so sorry if this is overly basic.

I have found this script that, when run inline, returns your IP.

<script type="text/javascript" src="http://l2.io/ip.js"></script>

http://l2.io/ip.js Has nothing more than a line of code that says

document.write('123.123.123.123');

(But obviously with the user's IP address)

I want to use this IP address as a return string for a function defined externally (but still on my domain).

I.e.

function getIP() {
    return (THAT SCRIPT'S OUTPUT);
}

Herein lies the issue; I can't figure out how to do this.

Etheryte
  • 24,589
  • 11
  • 71
  • 116
Aidan
  • 27
  • 6
  • 1
    That file http://l2.io/ip.js isn't pure javascript, but the code it displayed is rendered by some server side code. You could retrieve the content of that file and extract the ip from it – Sander Visser Jun 05 '14 at 13:42
  • 1
    Why not put your "getIP()" function which returns the IP into the external script file and then call it from your code – chrisarton Jun 05 '14 at 13:45
  • 1
    There seems to be [an exact dup](http://stackoverflow.com/questions/17414972/get-ip-address-with-javascript) with a working solution. – Teemu Jun 05 '14 at 13:55

1 Answers1

0

Bit of a hack but you could do something like this

<body>
  <div id="externalip">
    <script type="text/javascript" src="http://l2.io/ip.js"></script>
  </div>
  <script>
    var ip = $('#externalip').text();

    alert(ip);
  </script>
</body>
chrisarton
  • 4,401
  • 2
  • 18
  • 15