zoukankan      html  css  js  c++  java
  • 屏蔽某地区(城市)访问网站

    上级领导检查网站?百度竞价临时检查?你总会遇到各式各样的临时问题。以下代码可以实现指定地区(城市)禁止访问。原理是根据IP地址归属地区来进行筛选,进行跳转。

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" charset="GB2312" ></script>
    <script type=text/javascript>
     if(remote_ip_info.city =='成都'){
      window.location.href="跳转链接";
     }
    </script>

     由于http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪接口目前用不了,所以上面代码没法执行,下面讲用126网易接口的

    代码1:

    <!doctype html>
    <html>
    <head>
    <meta charset="gb2312">
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ip.ws.126.net/ipquery"></script>
    <script>
    var province=localAddress.province;//获取所在省,比如广东省
    var city=localAddress.city;//获取所在市,比如广州市
    //判断省
    if(province.indexOf('广东')  != -1){
        alert(province);    
        }else{
            }
    //判断市
    if(city.indexOf('广州')  != -1){
        alert(city);    
        }else{
            }
    </script>
    </head>
    <body>
    <p>12345678</p>
    </body>
    </html>

    代码2:

    <!doctype html>
    <html>
    <head>
    <meta charset="gb2312">
    <title>无标题文档</title>
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script>
    $.getScript('http://ip.ws.126.net/ipquery', function(){  
         console.log(localAddress.city)
        if(localAddress.city.indexOf('北京') != -1||localAddress.city.indexOf('杭州') != -1||localAddress.city.indexOf('上海') != -1||localAddress.city.indexOf('广州') != -1||localAddress.city.indexOf('深圳') != -1||localAddress.city.indexOf('东莞') != -1||localAddress.city.indexOf('房山') != -1){        
           window.location.href = 'http://www.baidu.com';      
        }else{        
         return;      
        }
        console.log(localAddress.province)    
        if(localAddress.province.indexOf('福建') != -1){        
           window.location.href = 'http://www.baidu.com';      
        }else{        
         return;      
        }    
    });
    </script>
    </head>
    
    <body>
    <p>123456789</p>
    
    
    </body>
    </html>
    转载请注明出处: 欢迎留言或qq(1090413588)交流
  • 相关阅读:
    数字电路与系统-公式规则知识点
    数字电路与系统-门电路基本知识1
    数字电路与系统-数制与编码2
    数字电路与系统-数制与编码1
    数字电路与系统-知识点2
    数字电路与系统-知识点1
    数字电路与系统-编码器
    数字电路与系统-组合逻辑电路的竞争冒险现象3
    数字电路与系统-组合逻辑电路的竞争冒险现象2
    前端工程师提高工作效率的几个小技巧
  • 原文地址:https://www.cnblogs.com/linyusong/p/6408658.html
Copyright © 2011-2022 走看看