在JavaScript中獲得HTTP請(qǐng)求的Referer

Js中獲取HTTP請(qǐng)求的上一次訪問(wèn)來(lái)源地址


JavaScript window.location對(duì)象


/**
 * 獲取HTTP請(qǐng)求的Referer
 * @ishost 布爾類型 Referer為空時(shí)是否返回Host(網(wǎng)站首頁(yè)地址)
 */
function get_http_referer(ishost) {
    if (ishost === undefined) { ishost = true; }
    if (document.referrer) {
        return document.referrer;
    } else {
        if (ishost) {
            return window.location.protocol   "http://"   window.location.host;
        } else {
            return "";
        }
    }
}


原文鏈接:在JavaScript中獲得HTTP請(qǐng)求的Referer