Get google (yahoo, bing) search by Javascript

If somebody need:

A small function to Get google (yahoo, bing) search's by Javascript.

keyword = function(){
 var dr=d.referrer,q,fq,goo='';
 if(dr.match(/ogle\.c|ahoo\.c|bing.c/i)){
  if((q=dr.indexOf('q='))>0){
   fq = dr.indexOf('&',q);
   goo = dr.substring(q+2,(fq>q?fq:dr.length));
  }
 }
 return goo;
}


To use, just call "keyword":

var palavrachave = keyword();
if(palavrachave){
  alert("Hi, welcome to my website. You are searching " + palavrachave);
}


Bye.

No comments:

Post a Comment