js如何判断访问是来自搜索引擎还是直接访问

js如何判断访问是来自搜索引擎还是直接访问,第1张

判断reffer来源,为空(即直接输入)就转向A网站,有来源就转向B网站。也可以更精确地判断来自哪个域名,哪个网站来选择转向的地址。

php:$_SERVER['>

n 推荐人,上线;介绍人 (其正确英语拼法是referrer,由于早期>

网络意义:

referrer 网站来路;访问者进入 网站的任何途径。 >

>

The Referer request-header field allows the client to specify, for the server's benefit, the address (URI) of the resource from which the Request-URI was obtained via

有趣的是,当时这个单词被他拼错了,正确的拼写应该是 Referrer。但是这个错误被发现之前,已经被大量使用,如果要改过来需要所有服务端、客户端的一致配合,还有大量的代码需要排查修改。于是,>

The Referer[sic] request-header field allows the client to specify, for the server's benefit, the address (URI) of the resource from which the Request-URI was obtained (the "referrer", although the header field is misspelled) via

可以看到,相比 >

由此可见,>

Nginx:ngx_>

PHP:$_SERVER['>

Django:>

ThinkJS:Controllerreferer() - 获取 referer;

JavaScript 中的 Referrer

这里说的 JavaScript,都是针对宿主为浏览器的场景,获取到的 referrer 属性都是由浏览器提供的。这一次,浏览器们比较齐心,都采用了正确的拼写方式,没有让这个错误在 JavaScript 中延续。

例如 DOM Level 2 里定义的 documentreferrer:

Returns the URI [IETF RFC 2396] of the page that linked to this page The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark) via

最新的 Fetch API 中的 Request 接口,也有一个名为 referrer 的属性:

The referrer attribute's getter must return the empty string if request's referrer is no referrer, "about:client" if request's referrer is client and request's referrer, serialized, otherwise via

更多关于 Fetch API 的介绍可以查看月影大大翻译的这篇文章:这个API很“迷人”——(新的Fetch API)。

其他标准中的 Referrer

其他标准,例如 Referrer Policy,也采用了正确的写法,并且明确表示不会兼容错误的拼写,例如在 Delivery via CSP 这一节写着:

Note: The directive name does not share the >

结论

>

JS:

1、documentreferrer 获取上一页的URL

2、documentURL 获取当前页的URL(注:URL必须大写)

C#:

RequestUrlReferrerAbsoluteUri

<script type="text/javascript">

if(self!=top){toplocation=selflocation;}

var ref=documentreferrer;

var domains=new Array("baidu/","sina/","google");

var refpass=false;

for(i=0;i<=domainslength;i++)

{

if(refindexOf(domains[i])>0)

{refpass=true;break;}

}

if(ref=="")

{refpass=true}

if(!refpass)

{windowlocationhref='tukelangcom';}

</script>

以上就是关于js如何判断访问是来自搜索引擎还是直接访问全部的内容,包括:js如何判断访问是来自搜索引擎还是直接访问、js/jquery如何获取iframe父页面的地址、referer 是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9300578.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存