在JavaScript中获得HTTP请求的Referer

Js中获取HTTP请求的上一次访问来源地址


JavaScript window.location对象


01/**
02 * 获取HTTP请求的Referer
03 * @ishost 布尔类型 Referer为空时是否返回Host(网站首页地址)
04 */
05function get_http_referer(ishost) {
06    if (ishost === undefined) { ishost = true; }
07    if (document.referrer) {
08        return document.referrer;
09    } else {
10        if (ishost) {
11            return window.location.protocol   "//"   window.location.host;
12        } else {
13            return "";
14        }
15    }
16}


原文链接:在JavaScript中获得HTTP请求的Referer