最新消息: 新版网站上线了!!!

利用js获取搜索引擎的关键字搜索的方法

var refer=document.referrer; //搜索来源页
var sosuo=refer.split(".")[1];
var grep=null;
var str=null;
var keyword=null;
switch(sosuo){
  case "baidu":
    grep=/wd\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
  break;
  case "google":
    grep=/q\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
  case "sogou":
    grep=/query\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
   case "soso":
    grep=/query\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
   case "bing":
    grep=/q\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
  case "yahoo":
    grep=/p\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
  case "soso":
    grep=/query\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
    case "so":
    grep=/q\=.*\&/i;
    str=refer.match(grep)
    keyword=str.toString().split("=")[1].split("&")[0];
	console.log(document.referrer);
    console.log(decodeURIComponent(keyword));
  break;
}
.....

转载请注明:谷谷点程序 » 利用js获取搜索引擎的关键字搜索的方法