Use an external function as a variable?

Hi -

I know very little about Javascript. I’m trying to use a function to specify a condition for an if statement. I can’t edit the function because it is external.

Specifically; I am trying to use a geolocation service (geoPlugin to geolocate your visitors) to taylor part of my wesite. The service provides javascript functions [URL=“http://www.geoplugin.net/javascript.gp”]here.

I am only interested in knowing which continent the visitor is from -

function geoplugin_continentCode() { return ‘EU’;}

In my case this function returns EU. What I want is to trigger a simple alert box onload but only where the continent code shows NA (which - I think - it will do if a visitor to my website is based in North America.)

I can’t figure out if there is a way to use a function return as a variable if one can’t edit the function? Or is this just something I can’t do with Javascript?

Its actually pretty simple, all you need to do is set a var to reference the function and alert the newly set var value.

var cc = geoplugin_countryCode();
alert(cc);

Thanks… I’m probably being really thick here, but where in this do I specify the function’s return (ie the continent code to differentiate between regions)?

You can do something like the below…

var cc = geoplugin_countryCode();

switch (cc) {
    case 'US':
        // United States
    break;
    case 'AU':
        // Australia
    break;
    case 'CN':
        // China
    break;
    default:
        // All other countries
}