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.

3
  • 1
    That file 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 Commented Jun 5, 2014 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 Commented Jun 5, 2014 at 13:45
  • 1
    There seems to be an exact dup with a working solution. Commented Jun 5, 2014 at 13:55

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.