首页 > 代码库 > referraluserid推广ID号跟踪JS处理A标签
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="http://www.mamicode.com/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 =http://www.mamicode.com/ GetQueryString(ruid); if (typeof (referraluserid) != "undefined") if (referraluserid != null && referraluserid != undefined && typeof referraluserid != "object" && (ruidValue =http://www.mamicode.com/= null || ruidValue =http://www.mamicode.com/="" || ruidValue =http://www.mamicode.com/= 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 = http://www.mamicode.com/typeof getReferraluserid_href =="function" ? getReferraluserid_href("?") : "";function getReferraluserid_href(a) { var hrefhttp://www.mamicode.com/= ""; var referraluserid = GetQueryString("referraluserid"); if (referraluserid != null && referraluserid != undefined && referraluserid != "") href = a + "referraluserid=" + referraluserid; return href;}
referraluserid推广ID号跟踪JS处理A标签
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。