Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show some content only in India. Provide the code to show blogger widget only in India.
I have tried following code and It doesn't work for me.

C#
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type='text/javascript'>
(function() {
  $.getJSON('http://ipinfo.io/?callback=?')
    .done(function( data ) {
      
      if (data.country == 'US') { // Country code goes here
        alert('#HTML6');
      }
</script>
Posted
Updated 21-Jul-15 20:17pm
v2

1 solution

The 'data' comes from the server so it could only tell you where the server is, while you want to display content according to the location of the client...
What you have to understand first of all, is that the actual location of the client may never be revealed...
There are two problems:
1. Privacy...the end user have all the right not let you know where he is
2. For devices (like desktop PC) without GPS the location decided based on IP address, which in almost every case the location of the ISP's computer farm...
In any case there is an API called Geolocation that supported by most of the modern browsers (as part of HTML5 support), you should use it: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation[^]
 
Share this answer
 
Comments
ankurchoudhary 22-Jul-15 2:28am    
I don't have good knowledge of coding. Therefore, explain how to implement it in blogger.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900