Skip to content

Instantly share code, notes, and snippets.

@Rakeshbagri
Created September 6, 2017 13:10
Show Gist options
  • Save Rakeshbagri/141832400aa720320d1f93f98a0f30da to your computer and use it in GitHub Desktop.
Save Rakeshbagri/141832400aa720320d1f93f98a0f30da to your computer and use it in GitHub Desktop.
How to auto call country name which country site open
<div id="hello" class="desktop-6 tablet-6 mobile-3">
<p><img class="contryflag" src="{{ 'earth.png' | file_url }}">{{ settings.hello }} <span id="country-name">Worldwide!</span></p>
</div>
<script>
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// example where I update content on the page.
// alert(location.country_code);
// jQuery('#city').html(location.city);
// jQuery('#region-code').html(location.region_code);
// jQuery('#region-name').html(location.region_name);
// jQuery('#areacode').html(location.areacode);
// jQuery('#ip').html(location.ip);
// jQuery('#zipcode').html(location.zipcode);
// jQuery('#longitude').html(location.longitude);
// jQuery('#latitude').html(location.latitude);
// jQuery('#country-name').html("To "+location.country+"!");
// jQuery('.country-name1').html("to "+location.country+"!");
jQuery('#country-name').html("To "+location.country_name+"!");
jQuery('.country-name1').html("to "+location.country_name+"!");
// jQuery('#country-code').html(location.country_code);
// var fl = JSON.stringify(location.country_code).toLowerCase();
var fl = location.country_code.toLowerCase();
// alert(fl);
// https://cdn.shopify.com/s/files/1/0790/4325/files/in.png
$('.contryflag').attr('src', 'https://cdn.shopify.com/s/files/1/0790/4325/files/'+fl+'.png');
}
} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment