使javascript不';不在特定国家运行

使javascript不';不在特定国家运行,javascript,Javascript,我有一个javascript重定向脚本。当这个国家是我们的时候,它就会改变方向 <script> function determineCountry(data){ switch(data.address.country_code){ case "US" : document.location.href = "http://xxxxxxxx.biz/theme.php"; break; } } </script>

我有一个javascript重定向脚本。当这个国家是我们的时候,它就会改变方向

<script>
function determineCountry(data){
   switch(data.address.country_code){
      case "US" :
         document.location.href = "http://xxxxxxxx.biz/theme.php";
      break;
   }    
}
</script>
<script type="text/javascript" src="http://api.wipmania.com/jsonp?callback=determineCountry"></script>

函数确定国家(数据){
开关(数据、地址、国家/地区代码){
案例“美国”:
document.location.href=”http://xxxxxxxx.biz/theme.php";
打破
}    
}
现在我想要的是相反的结果。比如,当国家是我们的时候,不要运行脚本

<script>
function determineCountry(data){
   switch(data.address.country_code){
      case "US" :
         document.location.href = "http://xxxxxxxx.biz/theme.php";
      break;
   }    
}
</script>
<script type="text/javascript" src="http://api.wipmania.com/jsonp?callback=determineCountry"></script>

提前感谢

如果国家是“美国”,只需稍作休息。在
默认值
开关
部分更改
document.location.href

function determineCountry(data){
   switch(data.address.country_code){
      case "US" :
         break;
      default:
         document.location.href = "http://xxxxxxxx.biz/theme.php";
   }    
}

如果条件为真,则会发生开关中的情况。也就是说,在您的案例中,如果
data.address.country\u code==“US”
案例将被解雇

如果未找到符合条件的案例,将使用默认案例(如果设置了一个)。
如果您希望重定向几个国家,但不是所有国家,则将这些国家添加到交换机中,即应该重定向的国家,否则您只需将它们排除在外

function determineCountry(data){
  switch(data.address.country_code){
  case "SE" :
     document.location.href = "http://xxxxxxxx.biz/theme.php"; 
     break;
   }    
}

determineCountry('SE'); // Will redirect.
determineCountry('US'); // Will not redirect.
determineCountry('CZ'); // Will not redirect.
您还可以将所有要重定向到列表的国家/地区添加到列表中,并在以下情况下使用单个

var codesToRedirectOn = ['SE', 'IT'];
function redirectIfCountry(code) {
  if(codesToRedirectOn.indexOf(code) !== -1) {
    // Redirect.
  }
  // Don't redirect (i.e., do nothing). 
}

但是,当在客户端执行逻辑时,需要注意的一点是客户端代码始终在客户端手中。如果客户端愿意,可以轻松地绕过重定向代码。

如果您想让它更安全,应该在加载页面之前在服务器端执行重定向。

这是一个重定向,而不是运行脚本。那么,当国家是美国时,你只是想不重定向吗?
case“US”:return?只是不将国家/地区案例添加到交换机?这将很容易被知道如何打开开发工具的人忽略,仅供参考。
case“US”:return非working@jite你是说把所有国家的名字都加上?没有别的选择吗。就像从一个程序员的角度。我还认为这个重定向脚本在页面运行时起作用。因此,有人如何能阻止重定向,快速坦克。也谢谢你的客户端信息。但不幸的是,我的cms不支持服务器端