如何仅在印度显示博客小部件? [英] How to display blogger widget only in india?

查看:51
本文介绍了如何仅在印度显示博客小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在印度展示一些内容。提供仅在印度显示博客小部件的代码。

我尝试过以下代码,它对我不起作用。



< pre lang =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(数据){

if (data.country == ' US'){ // 国家代码在这里
alert(' #HTML6');
}
< / script >

解决方案

.getJSON(' < span class =code-string> http://ipinfo.io/?callback=?')
.done(function(data){

if (data.country == ' US') { // 国家代码在这里
alert(' #HTML6');
}
< / script >


数据来自服务器,因此它只能告诉您服务器的位置,而您希望根据位置显示内容客户的意见...

首先要了解的是,客户的实际位置可能永远不会泄露...

有两个问题:

1.隐私......最终用户有权利不让你知道他在哪里

2.对于没有GPS的设备(如台式电脑)根据IP地址确定的位置,几乎在每种情况下都是ISP计算机场的位置...

无论如何,大多数现代浏览器都支持一种名为Geolocation的API(作为一部分) HTML5支持),您应该使用它: https://developer.mozilla.org/ en-US / docs / Web / API / Geolocation / Using_geolocation [ ^ ]


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.

<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>

解决方案

.getJSON('http://ipinfo.io/?callback=?') .done(function( data ) { if (data.country == 'US') { // Country code goes here alert('#HTML6'); } </script>


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[^]


这篇关于如何仅在印度显示博客小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆