function fnGetQueryString(key) { //正则获取url后面的参数值,如?env=dev&exp=123中可以通过fnGetQueryString('exp')=>得到123
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
var result = window.location.search.substr(1).match(reg);
return result ? decodeURIComponent(result[2]) : false;
};
function funcUrlDel(name) {//删除url指定参数名并返回新的url
var loca = window.location;
var baseUrl = loca.origin + loca.pathname + "#/activity";
var query = loca.search.substr(1);
if (query.indexOf(name) > -1) {
var obj = {};
var arr = query.split("&");
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i].split("=");
obj[arr[i][0]] = arr[i][1];
};
delete obj[name];
var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
return url
};
};
function refreshUrl() {//强制刷新到不带二次分享参数页面
var url = "";
if (fnGetQueryString('from')) {//from为微信二次分享自带参数
url = funcUrlDel('from');
if (fnGetQueryString('isappinstalled')) {//isappinstalled为微信二次分享自带参数 //截取去除isappinstalled参数后的地址
url=url.split('isappinstalled=0')[0];
window.location.href = url+'?activityId='+$routeParams.activityId+'&orgClueId='+$routeParams.orgClueId;
} else {
window.location.href = url+'?activityId='+$routeParams.activityId+'&orgClueId='+$routeParams.orgClueId;
}
}
};
if (fnGetQueryString('from')||fnGetQueryString('isappinstalled')) {
refreshUrl();
}
网友评论