单页应用获取 Referrer Url

//因为单页面应用的特殊性,需要手动计算 refurl
var _getRefUrl = function(absUrl, refUrl) {
    var tempAbsUrl = sessionStorage.getItem(‘absUrl’);
    var tempRefUrl = sessionStorage.getItem(‘refUrl’)
    if(tempAbsUrl === null && tempRefUrl === null) { 
        //首次进入系统
        //存入本地存储
        tempAbsUrl = absUrl;
        sessionStorage.setItem(‘absUrl’, absUrl);
        tempRefUrl = refUrl;
        sessionStorage.setItem(‘refUrl’, refUrl);
    } else if(absUrl !== tempAbsUrl) { 
        //当前页面不等于缓存的页面,说明已切换页面。替换缓存中的refurl
        sessionStorage.setItem(‘refUrl’, tempAbsUrl);
        tempRefUrl = tempAbsUrl;
        sessionStorage.setItem(‘absUrl’, absUrl);
        tempAbsUrl = absUrl;
    }

    return {‘absUrl’: tempAbsUrl, ‘refUrl’: tempRefUrl};
}

调用函数 _getRefUrl(location.absUrl(), window.document.referrer); 注:location.absUrl()是angularjs获取当前页面的url方法;

你可能感兴趣的:(单页应用获取 Referrer Url)