zoukankan      html  css  js  c++  java
  • 如何使用jQuery实现根据不同IP显示不同的内容

    一些SEM的投放页会针对不同地域做针对性的内容推广,下面我把实现方法分享出来。

    一、引用新浪提供的IP查询的js库

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" type="text/ecmascript"></script>

    二、在网页中添加一下js代码

    <script>
    
            if (navigator.userAgent.match(/mobile/i)) {
                var aid = GetQueryString('aid');
                var diqu = remote_ip_info["country"] + remote_ip_info["province"] + remote_ip_info["city"];
                if (diqu.indexOf('北京') < 0 && diqu.indexOf('广东') < 0 && diqu.indexOf('成都') < 0) {
                    //写你要做的事
    
                    //滑动跳转
                    $(function () {
                        $('body').bind("touchmove", function (event) {
                            if (aid != null) {
                                window.location.href = "http://bmf.bydsm.cn/ttfp330.html?aid=" + aid;
                            } else {
                                window.location.href = "http://bmf.bydsm.cn/ttfp330.html";
                            }
                        });
                    });
                }
            }
    
            function GetQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        </script>
    
  • 相关阅读:
    jsp数据交互二
    jsp数据交互(一)
    JQuery操作DOM
    事件和动画
    Jquery选择器
    Optional容器(jdk1.8)
    java常见集合笔记
    字符串内存占用图解
    单例设计模式
    代码块
  • 原文地址:https://www.cnblogs.com/ydcnblog/p/9289981.html
Copyright © 2011-2022 走看看