现在的位置: 网页制作教程网站制作教程 >正文
JavaScript脚本

JavaScript返回referer

发表于2017/3/7 网站制作教程 0条评论 ⁄ 热度 1,814℃

JavaScript获取HTTP请求的Referer。

ishost 布尔类型 Referer为空时是否返回Host(网站首页地址)

function get_http_referer(ishost) {
 if (ishost === undefined) { ishost = true; }
 if (document.referrer) {
  return document.referrer;
 } else {
  if (ishost) {
   return window.location.protocol + "//" + window.location.host;
  } else {
   return "";
  }
 }
}
  • 暂无评论