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)交流
  • 相关阅读:
    “浪潮杯”第九届山东省ACM大学生程序设计竞赛 F: Four-tuples容斥定理
    B
    C. Tourist Problem 2021.3.29 晚vj拉题 cf 1600 纯数学题
    C. Sum of Cubes
    Day29、Python中的异常处理及元类
    isinstance,issubclass,反射,内置方法(__str__,__del__,__call__)
    绑定方法与非绑定方法;classmethod及staticmethod装饰器
    组合,多态,封装
    类的继承
    面向对象编程思想基本介绍,类与对象的基本使用,属性查找,绑定方法
  • 原文地址:https://www.cnblogs.com/linyusong/p/6408658.html
Copyright © 2011-2022 走看看