page loader

Javascript, Visitor Geolocation and IP Address

Javascript is a language that is widely used in web development to determine visitor geolocation that can be utilized for creating dynamic web content. However before you utilize Javascript, you will need a service that can convert a visitor’s IP address to a meaningful geolocation in the world i.e. a particular country, state or city.

 

Geolify is perfect for providing highly accurate IP to location services and is widely used in a multitude of websites to obtain visitor geolocation. Without the requirement for any IP to location databases to be installed in your web server, Geolify makes it extremely easy to determine visitor location from IP address.

 

To make it even easier, Geolify comes built in with a single line Javascript request which you can paste into your website’s HTML HEAD tags and it will automatically obtain visitor geolocation of each visitor that on your website. To utilize this visitor geolocation, you simply have to type in Geolify’s Javascript functions in your website’s HTML HEAD or BODY. These functions will enable you to obtain visitor country, state, city, latitude and longitude in Javascript.

 

 

Geolify’s Javascript Visitor Location Tool Usage Below:

 

Geo Javascript HTML HEAD Code

Sign up for Geolify and create a new ‘Geo Java’ service. You will then be given a line of Java code similar to the one below. This Geo Javascript code needs to be pasted inbetween your website’s HTML HEAD tags. This code will perform IP extraction of your visitors and provide access to Geo Javascript functions that can be used to determine visitor country, region and city. Each user gets their own unique ID that can only be utilized on their website.

<script type=’text/javascript’ src=’http://www.geolify.com/geojavascript.php?id=638′ ></script>

 

 

Geo Javascript Functions

To get visitor’s location, use the Javascript functions provided below in your website’s HTML HEAD or BODY area. Examples are provided for your assistance.

 

Country Continent Code Function: geolify_continent_code() 

Country Continent Name Function: geolify_continent_name()

Country Country Code Function: geolify_country_code()

Country Name Function: geolify_country_name()

Region Name Function: geolify_region_name()

City Name Function: geolify_city_name()

Latitude Function: geolify_latitude()

Longitude Function: geolify_longitude()

 

 

Example: Displaying Visitor Country

<script type=”text/javascript” language=”Javascript”>

document.write(“Welcome visitors from “+geolify_country_name());

</script>

 

Example: Display Image To Visitor From Particular City

Note: Geolify has a built in Geo Image tool that can be used to display different images based on visitor location, so you don’t really need to write such code below !

if (geolify_city_name()==”New York”)

{

var cacheImage = document.createElement(‘img’);

cacheImage.src = ‘http://www.example.com/images/newyorkimage.jpg’;

cacheImage.setAttribute(“alt”, “welcome new yorkers”);

document.getElementById(“placehere”).appendChild(cacheImage);

}

else

{

var cacheImage = document.createElement(‘img’);

cacheImage.src = ‘http://www.example.com/images/worldimage.jpg’;

cacheImage.setAttribute(“alt”, “welcome world”);

document.getElementById(“placehere”).appendChild(cacheImage);

}

</script>

 

 

 

 

GEOLIFY

#1 Geo Targeting SaaS

Geo Redirects

Geo Content

Geo Popups

Geo Images

Geo Notifications

Geo Links

Geo Javascript

Get Started For Free