zoukankan      html  css  js  c++  java
  • referraluserid推广ID号跟踪JS处理A标签

     网站推广ID号跟踪

    xxx.html?referraluserid=123

    referraluserid.js   JS源文件 

    referraluserid的参数会自动绑定页面A标签

    有时是Post 表单跳转时不传数会丢失,这时可以根据后台或其它方式重新打印到前台页面,让Js重新获取到

    <script type="text/javascript">

      var referraluserid = '<%=BackReferraluserid%>';// BackReferraluserid 为后台值绑定到Js变量

    </script>

    紧接着引用JS文件

    <script type="text/javascript" src="/Scripts/referraluserid.js"></script>

    document.write("<input type='hidden' id='referraluserid' name='referraluserid' />");
    
    $(document).ready(function () {
        $("a").each(function () {
            if ($(this).attr("href") == "#" || $(this).attr("href") == "") {
                $(this).attr("href", "/");
            }
        });
        addUrlParse("referraluserid");
    });
    function getUrlParams() {
        var search = window.location.search;
        var tmparray = search.substr(1, search.length).split("&");
        var paramsArray = new Array;
        if (tmparray != null) {
            for (var i = 0; i < tmparray.length; i++) {
                var reg = /[=|^==]/;
                var set1 = tmparray[i].replace(reg, '&');
                var tmpStr2 = set1.split('&');
                var array = new Array;
                array[tmpStr2[0]] = tmpStr2[1];
                paramsArray.push(array);
            }
        }
        return paramsArray;
    }
    
    
    
    function GetQueryString(name) {
        var paramsArray = getUrlParams();
        if (paramsArray != null) {
            for (var i = 0; i < paramsArray.length; i++) {
                for (var j in paramsArray[i]) {
    
                    if (j.toLowerCase() == name.toLowerCase()) {
                        return paramsArray[i][j];
                    }
                }
            }
        }
        return null;
    }
    
    // typeof addUrlParse == "function" ?  addUrlParse("referraluserid") : "";
    function addUrlParse(ruid) {
    
        var ruidValue = GetQueryString(ruid);
        if (typeof (referraluserid) != "undefined")
            if (referraluserid != null && referraluserid != undefined && typeof referraluserid != "object" && (ruidValue == null || ruidValue == "" || ruidValue == undefined)) {
                ruidValue = referraluserid;
            }
        if (ruid != "" && ruid != null && ruidValue != "" && ruidValue != null) {
            var aStr = ruid + "=" + ruidValue;
    
            var url = window.location.search;
            try {
                $("a").each(function (i) {
                    var hrefstr = $(this).attr("href");
                    if (hrefstr != null && hrefstr != "" && hrefstr.indexOf("javascript:") < 0) {
                        var jinghao = "";
                        if (hrefstr.indexOf("#") > 0) {
                            var arr = hrefstr.split("#");
                            hrefstr = arr[0];
                            jinghao = arr[1];
                        }
                        if (hrefstr.indexOf("#") == -1) {
                          
                            if (hrefstr.toLowerCase().indexOf(ruid + "=") == -1)
                                hrefstr = hrefstr + (hrefstr.indexOf("?") > 0 ? "&" + aStr : "?" + aStr);
                            if (jinghao != "") {
                                hrefstr += "#" + jinghao;
                            }
                            $(this).attr("href", hrefstr);
                        }
    
                    }
                });
            }
            catch (e) {
                alert(e);
            }
        }
    }
    //  var referraluserid = typeof getReferraluserid == "function" ? getReferraluserid() : "";
    function getReferraluserid() { 
        return GetQueryString("referraluserid");
    }
    
    //var and_href = typeof getReferraluserid_href == "function" ? getReferraluserid_href("?") : "";
    function getReferraluserid_href(a) {
        var href = "";
        var referraluserid = GetQueryString("referraluserid");
        if (referraluserid != null && referraluserid != undefined && referraluserid != "")
            href = a + "referraluserid=" + referraluserid; 
    
        return href;
    }
    View Code
  • 相关阅读:
    阿里安全归零实验室招聘各路大牛!offer好说!
    露脸!钉钉通过SOC2隐私性原则审计,安全和隐私保护达超一流国际标准
    BAT齐聚阿里安全-ASRC生态大会:呼吁联合共建网络安全白色产业链
    v3-4_-vict-、-vinc-胜利,征服
    Grammar01 语法七要素之一_词类
    Grammar00_英语学习铁律
    SpokenEnglish01_ When's it due?
    SpringBoot31 重识Spring01-环境搭建、Actuator监控、属性配置、多环境配置
    Shrio04 自定义Realm
    Shrio03 Authenticator、配置多个Realm、SecurityManager认证策略
  • 原文地址:https://www.cnblogs.com/yonsy/p/4213655.html
Copyright © 2011-2022 走看看