Can anyone tell me how to call one javascript function if page is loaded in India and call another javascript function if page is loaded in other country.
Asked
Active
Viewed 173 times
1
-
You'd need to use PHP to retrieve what coutry the visitor is in. Or is it possible in pure JS? – D4V1D Mar 27 '15 at 12:15
-
Use geolocation + google maps to retrieve the user country: http://stackoverflow.com/questions/6747833/how-can-i-find-a-user-s-country-using-html5-geolocation – Fabrizio Calderan Mar 27 '15 at 12:19
-
https://docs.shopify.com/manual/configuration/store-customization/page-specific/store-wide/get-a-visitors-location – Abdulla Nilam Mar 27 '15 at 12:19
-
A JS-only solution on modern browsers seems possible, Have a look at the [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation). To convert lat/lng pairs to country codes see [Google's ReverseGeocoding](https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding) (You'll have to extract the relevant info from the json/xml delivered). See Fabrizio Calderan's linked SO answer – collapsar Mar 27 '15 at 12:21
1 Answers
0
For that you need to get Visitor region. This Code help You to find that. Reffer
<script type="text/javascript" src="http://www.google.com/jsapi?key=API_KEY_GOES_HERE"></script>
Then main script
<script type="text/javascript">
if(google.loader.ClientLocation)
{
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
}
else
{
document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
}
</script>
After this find your client Region call the JavaScript to by region name.
- store value of the country.
- Call the JavaScript Functions Which you want call. Reffer

Abdulla Nilam
- 36,589
- 17
- 64
- 85