How does js determine whether access is from a search engine (SPIDER) or direct access? js spider
The following javascript script code can be used to determine whether the access is 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 (); // convert it to lower case 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 = 'url to jump to '; window. adworkergo = 'ad _ app6' ;}}</script>
This JS method for determining the spider source is described in the onload of the body. That is, when the page is loaded, it is judged. 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 is not very useful for determining the source of a spider. Especially when it is necessary to determine more spider sources, code writing is troublesome.