0

Had this closed once as a duplicate, yet the so-called duplicate DID NOT actually address my whole question.

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. That is, I have a "scripts.js" that contains all the scripts I wish to use, and I would like to include it in that list as a local function that calls to the 12.io function, but javascript won't allow the <> tags, so I am unsure as to how to do this.

I.e.

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

This is the topic this was supposedly a duplicate of, and it is very similar.

Get client IP address via third party web service

However, this DOES NOT address defining as a forwarded script it in my own script file.

1
  • Hm, I'm tempted to close this as a duplicate again - the answer basically is read the docs of the site you are using. Commented Jun 6, 2014 at 3:20

1 Answer 1

2

As you seem to want your site's users' IP to be used, you'll need to have client-side code to have their browsers make the request to http://l2.io/ip.

You will need AJAX. Using jQuery's AJAX API:

$.get("http://l2.io/ip.js")
    .done(function(ip) {
        // do whatever you like with the ip...
    })
    .fail(function(err) {
        console.log(err);
    }); 

According to Bergi (and with reason), the data should never leave the callback to avoid synchronism problems. It's advisable to use promises.

Sign up to request clarification or add additional context in comments.

8 Comments

Simply don't load http://l2.io/ip.js but http://l2.io/ip - there's no need to extract the IP address.
I don't know the site; I'm using what the OP gave me! Thanks, anyway.
It's basically described in the duplicated he linked :-)
Gah, that was edited after I answered, or while I was.
Ok, only the relevant part's left.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.