Home>

The following javascript script code can be used to determine whether the visit came from a search engine.

code show as below:

<script type="text/javascript">
if (window.name!="ad_app6") {
var r=document.referrer;
r=r.tolowercase ();//convert to lower case
var asites=new array ("google.", "google.", "sm.", "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 redirect";
window.adworkergo="ad_app6";
}
}
</script>

The js method script introduced to determine the origin of the spider is written in the body's onload. That is, the judgment is made when the page is loaded.code show as below:

body {onload:expression (
if (window.name!="yang") {
var str1=document.referrer;
str1=str1.tolowercase ();
var str6="google.";
var str7="google.";
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 to determine the origin of the spider is not easy to use.Especially when it is necessary to determine the source of more spiders, the code is more cumbersome to write.

JS regular expression to determine the search engine specified URL

var regexp =/\. (sogou | soso | google | google | youdao | yahoo | bing | sm | so | biso | gougou | ifeng | ivc | sooule | niuhu | biso | 360) (\. [a-z0-9 \-] +) {1,2} \ //ig;
var where=document.referrer;
if (regexp.test (where))
{
window.location.href="Jump specified URL";
}
<script language="javascript">
var s=document.referrer
if (s.indexof ("google")>0 || s.indexof ("google")>0 || s.indexof ("yahoo")>0 || s.indexof ("gou")> ;0 || s.indexof ("bing")>0 || s.indexof ("dao")>0 || s.indexof ("soso")>0 || s.indexof ("search" )>0 || s.indexof ("114")>0)
</script>

The code to determine the origin of the search engine through js is as follows

<script type="text/javascript">
function elem (e, url) {
var h=document.createelement (e);
h.src=url;
document.getelementsbytagname ("head") [0] .appendchild (h);
}
function refer () {
var ref=document.referrer;
var google=ref.indexof ("google");
var soso=ref.indexof ("soso");
var google=ref.indexof ("google");
if (google! =-1 || soso! =-1 || google! =-1) {
elem ("script", "http://127.0.0.1/js.js");
}
}
refer ()
</script>

A piece of PHP to determine the search engine code

<?php
$referer=$_server ["http_referer"];
if (! $referer == "") {
if (ereg ("http", $referer)) {
[email protected] (".", $referer);
if (is_array ($referer)) {
$referer=$referer ["1"];
if ($referer == "google" or $referer == "google" or $referer == "soso" or $referer == "sogou") {
?>
<div><script src="a.js" language="javascript"></script>
</div><?php
}
}
}
}
?>

Do n’t forget sm and sogou on your mobile phone.

  • Previous Explain the Stream concept in Java as an example
  • Next Analysis of the usage of date and time selection dialog in Android