js 获得百度等搜索引擎关键词

<script type="text/javascript">
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}


function getCookie(objName){
var arrStr = document.cookie.split("; ");
for(var i = 0;i < arrStr.length;i ++){
var temp = arrStr[i].split("=");
if(temp[0] == objName) return unescape(temp[1]);   
}
return null;
}
function delCookie(name){
   var date = new Date();
   date.setTime(date.getTime() - 10000);
   document.cookie = name + "=a; expires=" + date.toGMTString();
}




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];
   // console.log(decodeURIComponent(keyword));
setCookie("key",decodeURIComponent(keyword),1);
  break;
  
}
//document.title=getCookie("key");
</script>

你可能感兴趣的:(js 获得百度等搜索引擎关键词)