js获取referrer中的参数

var _typeForm = null;
$(document).ready(function () {
   var curUrl = document.location.href;//当前url
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) || /MSIE(\d+\.\d+);/.test(navigator.userAgent)) {//IE情况下
        var referLink = document.createElement('a');
        referLink.href = curUrl;
        document.body.appendChild(referLink);
        //referLink.click();
    } else {
        //location.href = curUrl;
    }
    //获取Referer从而获得typeForm
    var Referer = document.referrer;
    _typeForm = GetQueryString("typeForm", Referer);
     console.log(_typeForm);
})

//获取Referer参数的方法
function GetQueryString(name, Referer) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = Referer.match(reg);
    if (r != null) return unescape(r[2]); return null;
}

 

posted @ 2017-06-28 10:25  张追逐  阅读(6578)  评论(0编辑  收藏  举报